<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>date_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_date_date_test.js.html">date_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2006 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.dateTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.dateTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.array&#39;);
<a name="line19"></a>goog.require(&#39;goog.date&#39;);
<a name="line20"></a>goog.require(&#39;goog.date.Date&#39;);
<a name="line21"></a>goog.require(&#39;goog.date.DateTime&#39;);
<a name="line22"></a>goog.require(&#39;goog.date.Interval&#39;);
<a name="line23"></a>goog.require(&#39;goog.date.month&#39;);
<a name="line24"></a>goog.require(&#39;goog.date.weekDay&#39;);
<a name="line25"></a>goog.require(&#39;goog.i18n.DateTimeSymbols&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.ExpectedFailures&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line28"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line29"></a>goog.require(&#39;goog.userAgent.platform&#39;);
<a name="line30"></a>goog.require(&#39;goog.userAgent.product&#39;);
<a name="line31"></a>goog.require(&#39;goog.userAgent.product.isVersion&#39;);
<a name="line32"></a>
<a name="line33"></a>var expectedFailures;
<a name="line34"></a>
<a name="line35"></a>function shouldRunTests() {
<a name="line36"></a>
<a name="line37"></a>  // Test disabled in Chrome-vista due to flakiness. See b/2753939.
<a name="line38"></a>  if (goog.userAgent.product.CHROME &amp;&amp;
<a name="line39"></a>      goog.userAgent.WINDOWS &amp;&amp;
<a name="line40"></a>      goog.userAgent.platform.VERSION == &#39;6.0&#39;) {
<a name="line41"></a>    return false;
<a name="line42"></a>  }
<a name="line43"></a>
<a name="line44"></a>  return true;
<a name="line45"></a>}
<a name="line46"></a>
<a name="line47"></a>function setUpPage() {
<a name="line48"></a>  expectedFailures = new goog.testing.ExpectedFailures();
<a name="line49"></a>}
<a name="line50"></a>
<a name="line51"></a>function tearDown() {
<a name="line52"></a>  expectedFailures.handleTearDown();
<a name="line53"></a>}
<a name="line54"></a>
<a name="line55"></a>
<a name="line56"></a>/**
<a name="line57"></a> * Unit test for Closure&#39;s &#39;goog.date&#39;.
<a name="line58"></a> */
<a name="line59"></a>function testIsLeapYear() {
<a name="line60"></a>  var f = goog.date.isLeapYear;
<a name="line61"></a>
<a name="line62"></a>  assertFalse(&#39;Year 1900 was not a leap year (the 100 rule)&#39;, f(1900));
<a name="line63"></a>  assertFalse(&#39;Year 1901 was not a leap year (the 100 rule)&#39;, f(1901));
<a name="line64"></a>  assertTrue(&#39;Year 1904 was a leap year&#39;, f(1904));
<a name="line65"></a>  assertFalse(&#39;Year 1999 was not a leap year&#39;, f(1999));
<a name="line66"></a>  assertTrue(&#39;Year 2000 was a leap year (the 400 rule)&#39;, f(2000));
<a name="line67"></a>  assertTrue(&#39;Year 2004 was a leap year&#39;, f(2004));
<a name="line68"></a>  assertFalse(&#39;Year 2006 was not a leap year&#39;, f(2006));
<a name="line69"></a>}
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>function testIsLongIsoYear() {
<a name="line73"></a>  var f = goog.date.isLongIsoYear;
<a name="line74"></a>
<a name="line75"></a>  // see http://en.wikipedia.org/wiki/ISO_week_date#The_leap_year_cycle
<a name="line76"></a>  assertFalse(&#39;1902 was not an ISO leap year&#39;, f(1902));
<a name="line77"></a>  assertTrue(&#39;1903 was an ISO leap year&#39;, f(1903));
<a name="line78"></a>  assertFalse(&#39;1904 was not an ISO leap year&#39;, f(1904));
<a name="line79"></a>  assertTrue(&#39;1981 was an ISO leap year&#39;, f(1981));
<a name="line80"></a>  assertTrue(&#39;1987 was an ISO leap year&#39;, f(1987));
<a name="line81"></a>  assertFalse(&#39;2000 was not an ISO leap year&#39;, f(2000));
<a name="line82"></a>}
<a name="line83"></a>
<a name="line84"></a>
<a name="line85"></a>function testGetNumberOfDaysInMonth() {
<a name="line86"></a>  var f = goog.date.getNumberOfDaysInMonth;
<a name="line87"></a>
<a name="line88"></a>  assertEquals(&#39;January has 31 days&#39;, f(2006, goog.date.month.JAN, 2000), 31);
<a name="line89"></a>  assertEquals(&#39;February has 28 days&#39;, f(2006, goog.date.month.FEB), 28);
<a name="line90"></a>  assertEquals(&#39;February has 29 days (leap year)&#39;,
<a name="line91"></a>               f(2008, goog.date.month.FEB), 29);
<a name="line92"></a>  assertEquals(&#39;March has 31 days&#39;, f(2006, goog.date.month.MAR), 31);
<a name="line93"></a>  assertEquals(&#39;April has 30 days&#39;, f(2006, goog.date.month.APR), 30);
<a name="line94"></a>  assertEquals(&#39;May has 31 days&#39;, f(2006, goog.date.month.MAY), 31);
<a name="line95"></a>  assertEquals(&#39;June has 30 days&#39;, f(2006, goog.date.month.JUN), 30);
<a name="line96"></a>  assertEquals(&#39;July has 31 days&#39;, f(2006, goog.date.month.JUL), 31);
<a name="line97"></a>  assertEquals(&#39;August has 31 days&#39;, f(2006, goog.date.month.AUG), 31);
<a name="line98"></a>  assertEquals(&#39;September has 30 days&#39;, f(2006, goog.date.month.SEP), 30);
<a name="line99"></a>  assertEquals(&#39;October has 31 days&#39;, f(2006, goog.date.month.OCT), 31);
<a name="line100"></a>  assertEquals(&#39;November has 30 days&#39;, f(2006, goog.date.month.NOV), 30);
<a name="line101"></a>  assertEquals(&#39;December has 31 days&#39;, f(2006, goog.date.month.DEC), 31);
<a name="line102"></a>}
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>function testIsSameDay() {
<a name="line106"></a>  assertTrue(&#39;Dates are on the same day&#39;, goog.date.isSameDay(
<a name="line107"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line108"></a>      new Date(&#39;2009/02/01 01:15:49&#39;)));
<a name="line109"></a>
<a name="line110"></a>  assertFalse(&#39;Days are different&#39;, goog.date.isSameDay(
<a name="line111"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line112"></a>      new Date(&#39;2009/02/02 01:15:49&#39;)));
<a name="line113"></a>
<a name="line114"></a>  assertFalse(&#39;Months are different&#39;, goog.date.isSameDay(
<a name="line115"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line116"></a>      new Date(&#39;2009/03/01 01:15:49&#39;)));
<a name="line117"></a>
<a name="line118"></a>  assertFalse(&#39;Years are different&#39;, goog.date.isSameDay(
<a name="line119"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line120"></a>      new Date(&#39;2010/02/01 01:15:49&#39;)));
<a name="line121"></a>
<a name="line122"></a>  assertFalse(&#39;Wrong millennium&#39;, goog.date.isSameDay(
<a name="line123"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line124"></a>      new Date(&#39;1009/02/01 01:15:49&#39;)));
<a name="line125"></a>}
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>function testIsSameMonth() {
<a name="line129"></a>  assertTrue(&#39;Dates are on the same day&#39;, goog.date.isSameMonth(
<a name="line130"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line131"></a>      new Date(&#39;2009/02/01 01:15:49&#39;)));
<a name="line132"></a>
<a name="line133"></a>  assertTrue(&#39;Dates are in the same month&#39;, goog.date.isSameMonth(
<a name="line134"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line135"></a>      new Date(&#39;2009/02/10 01:15:49&#39;)));
<a name="line136"></a>
<a name="line137"></a>  assertFalse(&#39;Month is different&#39;, goog.date.isSameMonth(
<a name="line138"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line139"></a>      new Date(&#39;2009/03/01 01:15:49&#39;)));
<a name="line140"></a>
<a name="line141"></a>  assertFalse(&#39;Year is different&#39;, goog.date.isSameMonth(
<a name="line142"></a>      new Date(&#39;2008/02/01 12:45:12&#39;),
<a name="line143"></a>      new Date(&#39;2009/02/01 01:15:49&#39;)));
<a name="line144"></a>
<a name="line145"></a>  assertFalse(&#39;Wrong millennium&#39;, goog.date.isSameMonth(
<a name="line146"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line147"></a>      new Date(&#39;1009/02/01 01:15:49&#39;)));
<a name="line148"></a>}
<a name="line149"></a>
<a name="line150"></a>
<a name="line151"></a>function testIsSameYear() {
<a name="line152"></a>  assertTrue(&#39;Dates are on the same day&#39;, goog.date.isSameYear(
<a name="line153"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line154"></a>      new Date(&#39;2009/02/01 01:15:49&#39;)));
<a name="line155"></a>
<a name="line156"></a>  assertTrue(&#39;Only days are different&#39;, goog.date.isSameYear(
<a name="line157"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line158"></a>      new Date(&#39;2009/02/11 01:15:49&#39;)));
<a name="line159"></a>
<a name="line160"></a>  assertTrue(&#39;Only months are different&#39;, goog.date.isSameYear(
<a name="line161"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line162"></a>      new Date(&#39;2009/02/01 01:15:49&#39;)));
<a name="line163"></a>
<a name="line164"></a>  assertFalse(&#39;Years are different&#39;, goog.date.isSameYear(
<a name="line165"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line166"></a>      new Date(&#39;2010/02/01 01:15:49&#39;)));
<a name="line167"></a>
<a name="line168"></a>  assertFalse(&#39;Years are different&#39;, goog.date.isSameYear(
<a name="line169"></a>      new Date(&#39;2009/02/01 12:45:12&#39;),
<a name="line170"></a>      new Date(&#39;2008/02/01 01:15:49&#39;)));
<a name="line171"></a>
<a name="line172"></a>}
<a name="line173"></a>
<a name="line174"></a>
<a name="line175"></a>function testGetWeekNumber() {
<a name="line176"></a>  var f = goog.date.getWeekNumber;
<a name="line177"></a>
<a name="line178"></a>  // Test cases from http://en.wikipedia.org/wiki/ISO_week_date#Examples
<a name="line179"></a>  assertEquals(&#39;2005-01-01 is the week 53 of the previous year&#39;, 53,
<a name="line180"></a>               f(2005, goog.date.month.JAN, 1));
<a name="line181"></a>  assertEquals(&#39;2005-01-02 is the week 53 of the previous year&#39;, 53,
<a name="line182"></a>               f(2005, goog.date.month.JAN, 2));
<a name="line183"></a>  assertEquals(&#39;2005-12-31 is the week 52&#39;, 52,
<a name="line184"></a>               f(2005, goog.date.month.DEC, 31));
<a name="line185"></a>  assertEquals(&#39;2007-01-01 is the week 1&#39;, 1,
<a name="line186"></a>               f(2007, goog.date.month.JAN, 1));
<a name="line187"></a>  assertEquals(&#39;2007-12-30 is the week 52&#39;, 52,
<a name="line188"></a>               f(2007, goog.date.month.DEC, 30));
<a name="line189"></a>  assertEquals(&#39;2007-12-31 is the week 1 of the following year&#39;, 1,
<a name="line190"></a>               f(2007, goog.date.month.DEC, 31));
<a name="line191"></a>  assertEquals(&#39;2008-01-01 is the week 1&#39;, 1,
<a name="line192"></a>               f(2008, goog.date.month.JAN, 1));
<a name="line193"></a>  assertEquals(&#39;2008-12-28 is the week 52&#39;, 52,
<a name="line194"></a>               f(2008, goog.date.month.DEC, 28));
<a name="line195"></a>  assertEquals(&#39;2008-12-29 is the week 1 of the following year&#39;, 1,
<a name="line196"></a>               f(2008, goog.date.month.DEC, 29));
<a name="line197"></a>  assertEquals(&#39;2008-12-31 is the week 1 of the following year&#39;, 1,
<a name="line198"></a>               f(2008, goog.date.month.DEC, 31));
<a name="line199"></a>  assertEquals(&#39;2009-01-01 is the week 1&#39;, 1,
<a name="line200"></a>               f(2009, goog.date.month.JAN, 1));
<a name="line201"></a>  assertEquals(&#39;2009-12-31 is the week 53 of the previous year&#39;, 53,
<a name="line202"></a>               f(2009, goog.date.month.DEC, 31));
<a name="line203"></a>  assertEquals(&#39;2010-01-01 is the week 53 of the previous year&#39;, 53,
<a name="line204"></a>               f(2010, goog.date.month.JAN, 1));
<a name="line205"></a>  assertEquals(&#39;2010-01-03 is the week 53 of the previous year&#39;, 53,
<a name="line206"></a>               f(2010, goog.date.month.JAN, 3));
<a name="line207"></a>  assertEquals(&#39;2010-01-04 is the week 1&#39;, 1,
<a name="line208"></a>               f(2010, goog.date.month.JAN, 4));
<a name="line209"></a>
<a name="line210"></a>  assertEquals(&#39;2006-01-01 is in week 52 of the following year&#39;, 52,
<a name="line211"></a>               f(2006, goog.date.month.JAN, 1));
<a name="line212"></a>  assertEquals(&#39;2006-01-02 is in week 1&#39;, 1,
<a name="line213"></a>               f(2006, goog.date.month.JAN, 2));
<a name="line214"></a>  assertEquals(&#39;2006-10-16 is in week 42&#39;, 42,
<a name="line215"></a>               f(2006, goog.date.month.OCT, 16));
<a name="line216"></a>  assertEquals(&#39;2006-10-19 is in week 42&#39;, 42,
<a name="line217"></a>               f(2006, goog.date.month.OCT, 19));
<a name="line218"></a>  assertEquals(&#39;2006-10-22 is in week 42&#39;, 42,
<a name="line219"></a>               f(2006, goog.date.month.OCT, 22));
<a name="line220"></a>  assertEquals(&#39;2006-10-23 is in week 43&#39;, 43,
<a name="line221"></a>               f(2006, goog.date.month.OCT, 23));
<a name="line222"></a>  assertEquals(&#39;2008-12-29 is in week 1 of the following year&#39;, 1,
<a name="line223"></a>               f(2008, goog.date.month.DEC, 29));
<a name="line224"></a>  assertEquals(&#39;2010-01-03 is in week 53 of the previous year&#39;, 53,
<a name="line225"></a>               f(2010, goog.date.month.JAN, 03));
<a name="line226"></a>
<a name="line227"></a>  assertEquals(&#39;2008-02-01 is in week 5&#39;, 5,
<a name="line228"></a>               f(2008, goog.date.month.FEB, 1));
<a name="line229"></a>  assertEquals(&#39;2008-02-04 is in week 6&#39;, 6,
<a name="line230"></a>               f(2008, goog.date.month.FEB, 4));
<a name="line231"></a>
<a name="line232"></a>  // Tests for different cutoff days.
<a name="line233"></a>  assertEquals(&#39;2006-01-01 is in week 52 of the prev. year (cutoff=Monday)&#39;, 52,
<a name="line234"></a>               f(2006, goog.date.month.JAN, 1, goog.date.weekDay.MON));
<a name="line235"></a>  assertEquals(&#39;2006-01-01 is in week 1 (cutoff=Sunday)&#39;, 1,
<a name="line236"></a>               f(2006, goog.date.month.JAN, 1, goog.date.weekDay.SUN));
<a name="line237"></a>  assertEquals(&#39;2006-12-31 is in week 52 (cutoff=Monday)&#39;, 52,
<a name="line238"></a>               f(2006, goog.date.month.DEC, 31, goog.date.weekDay.MON));
<a name="line239"></a>  assertEquals(&#39;2006-12-31 is in week 53 (cutoff=Sunday)&#39;, 53,
<a name="line240"></a>               f(2006, goog.date.month.DEC, 31, goog.date.weekDay.SUN));
<a name="line241"></a>  assertEquals(&#39;2007-01-01 is in week 1 (cutoff=Monday)&#39;, 1,
<a name="line242"></a>               f(2007, goog.date.month.JAN, 1, goog.date.weekDay.MON));
<a name="line243"></a>  assertEquals(&#39;2007-01-01 is in week 1 (cutoff=Sunday)&#39;, 1,
<a name="line244"></a>               f(2007, goog.date.month.JAN, 1, goog.date.weekDay.SUN));
<a name="line245"></a>
<a name="line246"></a>  // Tests for leap year 2000.
<a name="line247"></a>  assertEquals(&#39;2000-02-27 is in week 8&#39;, 8,
<a name="line248"></a>               f(2000, goog.date.month.FEB, 27));
<a name="line249"></a>  assertEquals(&#39;2000-02-28 is in week 9&#39;, 9,
<a name="line250"></a>               f(2000, goog.date.month.FEB, 28));
<a name="line251"></a>  assertEquals(&#39;2000-02-29 is in week 9&#39;, 9,
<a name="line252"></a>               f(2000, goog.date.month.FEB, 29));
<a name="line253"></a>  assertEquals(&#39;2000-03-01 is in week 9&#39;, 9,
<a name="line254"></a>               f(2000, goog.date.month.MAR, 1));
<a name="line255"></a>  assertEquals(&#39;2000-03-05 is in week 9&#39;, 9,
<a name="line256"></a>               f(2000, goog.date.month.MAR, 5));
<a name="line257"></a>  assertEquals(&#39;2000-03-06 is in week 10&#39;, 10,
<a name="line258"></a>               f(2000, goog.date.month.MAR, 6));
<a name="line259"></a>
<a name="line260"></a>  // Check that week number is strictly incremented by 1.
<a name="line261"></a>  var dt = new goog.date.Date(2008, goog.date.month.JAN, 1);
<a name="line262"></a>  for (var i = 0; i &lt; 52; ++i) {
<a name="line263"></a>    var expected_week = i + 1;
<a name="line264"></a>    assertEquals(dt.toUTCIsoString(true) + &#39; is in week &#39; + expected_week,
<a name="line265"></a>                 expected_week, dt.getWeekNumber());
<a name="line266"></a>    dt.add(new goog.date.Interval(goog.date.Interval.DAYS, 7));
<a name="line267"></a>  }
<a name="line268"></a>}
<a name="line269"></a>
<a name="line270"></a>
<a name="line271"></a>function testFormatMonthAndYear() {
<a name="line272"></a>  var f = goog.date.formatMonthAndYear;
<a name="line273"></a>  assertEquals(&#39;January 2008&#39;,
<a name="line274"></a>               f(goog.i18n.DateTimeSymbols.MONTHS[goog.date.month.JAN], 2008));
<a name="line275"></a>  assertEquals(&#39;Jun 2007&#39;,
<a name="line276"></a>               f(goog.i18n.DateTimeSymbols.SHORTMONTHS[goog.date.month.JUN],
<a name="line277"></a>                   2007));
<a name="line278"></a>}
<a name="line279"></a>
<a name="line280"></a>
<a name="line281"></a>//=== tests for goog.date.Date ===
<a name="line282"></a>function testIsDateLikeWithGoogDate() {
<a name="line283"></a>  var jsDate = new Date();
<a name="line284"></a>  var googDate = new goog.date.Date();
<a name="line285"></a>  var string = &#39;foo&#39;;
<a name="line286"></a>  var number = 1;
<a name="line287"></a>  var nullVar = null;
<a name="line288"></a>  var notDefined;
<a name="line289"></a>
<a name="line290"></a>  assertTrue(&#39;js Date should be date-like&#39;, goog.isDateLike(jsDate));
<a name="line291"></a>  assertTrue(&#39;goog Date should be date-like&#39;, goog.isDateLike(googDate));
<a name="line292"></a>  assertFalse(&#39;string should not be date-like&#39;, goog.isDateLike(string));
<a name="line293"></a>  assertFalse(&#39;number should not be date-like&#39;, goog.isDateLike(number));
<a name="line294"></a>  assertFalse(&#39;nullVar should not be date-like&#39;, goog.isDateLike(nullVar));
<a name="line295"></a>  assertFalse(&#39;undefined should not be date-like&#39;, goog.isDateLike(notDefined));
<a name="line296"></a>}
<a name="line297"></a>
<a name="line298"></a>
<a name="line299"></a>function testDateConstructor() {
<a name="line300"></a>  var date = new goog.date.Date(2001, 2, 3);
<a name="line301"></a>  assertEquals(2001, date.getFullYear());
<a name="line302"></a>  assertEquals(2, date.getMonth());
<a name="line303"></a>  assertEquals(3, date.getDate());
<a name="line304"></a>
<a name="line305"></a>  var date = new goog.date.Date(2001);
<a name="line306"></a>  assertEquals(2001, date.getFullYear());
<a name="line307"></a>  assertEquals(0, date.getMonth());
<a name="line308"></a>  assertEquals(1, date.getDate());
<a name="line309"></a>
<a name="line310"></a>  var date = new goog.date.Date(new Date(2001, 2, 3, 4, 5, 6, 7));
<a name="line311"></a>  assertEquals(2001, date.getFullYear());
<a name="line312"></a>  assertEquals(2, date.getMonth());
<a name="line313"></a>  assertEquals(3, date.getDate());
<a name="line314"></a>  assertEquals(new Date(2001, 2, 3).getTime(), date.getTime());
<a name="line315"></a>
<a name="line316"></a>  goog.now = function() {
<a name="line317"></a>    return new Date(2001, 2, 3, 4).getTime();
<a name="line318"></a>  };
<a name="line319"></a>  var date = new goog.date.Date();
<a name="line320"></a>  assertEquals(2001, date.getFullYear());
<a name="line321"></a>  assertEquals(2, date.getMonth());
<a name="line322"></a>  assertEquals(3, date.getDate());
<a name="line323"></a>  assertEquals(new Date(2001, 2, 3).getTime(), date.getTime());
<a name="line324"></a>}
<a name="line325"></a>
<a name="line326"></a>
<a name="line327"></a>function testDateConstructor_yearBelow100() {
<a name="line328"></a>  var date = new goog.date.Date(14, 7, 19);
<a name="line329"></a>  assertEquals(&#39;Date constructor should respect passed in full year&#39;,
<a name="line330"></a>      14, date.getFullYear());
<a name="line331"></a>
<a name="line332"></a>  var copied = new goog.date.Date(date);
<a name="line333"></a>  assertEquals(&#39;Copying a should return identical date&#39;,
<a name="line334"></a>      date.getTime(), copied.getTime());
<a name="line335"></a>  assertEquals(&#39;Full year should be left intact by copying&#39;,
<a name="line336"></a>      14, copied.getFullYear());
<a name="line337"></a>
<a name="line338"></a>  // Test boundaries.
<a name="line339"></a>  assertEquals(-1, new goog.date.Date(-1, 0, 1).getFullYear());
<a name="line340"></a>  assertEquals(&#39;There is no year zero, but JS dates accept it&#39;,
<a name="line341"></a>      0, new goog.date.Date(0, 0, 1).getFullYear());
<a name="line342"></a>  assertEquals(1, new goog.date.Date(1, 0, 1).getFullYear());
<a name="line343"></a>  assertEquals(99, new goog.date.Date(99, 0, 1).getFullYear());
<a name="line344"></a>  assertEquals(100, new goog.date.Date(100, 0, 1).getFullYear());
<a name="line345"></a>}
<a name="line346"></a>
<a name="line347"></a>
<a name="line348"></a>function testDateConstructor_flipOver() {
<a name="line349"></a>  var date = new goog.date.Date(2012, 12, 1);
<a name="line350"></a>  assertEquals(&#39;20130101&#39;, date.toIsoString());
<a name="line351"></a>
<a name="line352"></a>  date = new goog.date.Date(12, 12, 1);
<a name="line353"></a>  assertEquals(&#39;130101&#39;, date.toIsoString());
<a name="line354"></a>}
<a name="line355"></a>
<a name="line356"></a>
<a name="line357"></a>function testDateToIsoString() {
<a name="line358"></a>  var d = new goog.date.Date(2006, goog.date.month.JAN, 1);
<a name="line359"></a>  assertEquals(&#39;1 Jan 2006 is 20060101&#39;, d.toIsoString(), &#39;20060101&#39;);
<a name="line360"></a>
<a name="line361"></a>  d = new goog.date.Date(2007, goog.date.month.JUN, 12);
<a name="line362"></a>  assertEquals(&#39;12 Jun 2007 is 20070612&#39;, d.toIsoString(), &#39;20070612&#39;);
<a name="line363"></a>
<a name="line364"></a>  d = new goog.date.Date(2218, goog.date.month.DEC, 31);
<a name="line365"></a>  assertEquals(&#39;31 Dec 2218 is 22181231&#39;, d.toIsoString(), &#39;22181231&#39;);
<a name="line366"></a>}
<a name="line367"></a>
<a name="line368"></a>
<a name="line369"></a>function testRfc822StringToDate() {
<a name="line370"></a>  var date = goog.date.DateTime.fromRfc822String(&#39;October 2, 2002 8:00:00&#39;);
<a name="line371"></a>  assertNotNull(date);
<a name="line372"></a>  assertEquals(2002, date.getFullYear());
<a name="line373"></a>  assertEquals(9, date.getMonth());
<a name="line374"></a>  assertEquals(2, date.getDate());
<a name="line375"></a>  assertEquals(8, date.getHours());
<a name="line376"></a>  assertEquals(0, date.getMinutes());
<a name="line377"></a>  assertEquals(0, date.getSeconds());
<a name="line378"></a>  assertEquals(0, date.getMilliseconds());
<a name="line379"></a>  assertEquals(new Date(2002, 9, 2, 8).getTime(), date.getTime());
<a name="line380"></a>
<a name="line381"></a>  var date = goog.date.DateTime.fromRfc822String(
<a name="line382"></a>      &#39;Sat, 02 Oct 2010 08:00:00 UTC&#39;);
<a name="line383"></a>  assertEquals(2010, date.getFullYear());
<a name="line384"></a>  assertEquals(9, date.getUTCMonth());
<a name="line385"></a>  assertEquals(2, date.getUTCDate());
<a name="line386"></a>  assertEquals(8, date.getUTCHours());
<a name="line387"></a>  assertEquals(0, date.getUTCMinutes());
<a name="line388"></a>  assertEquals(0, date.getUTCSeconds());
<a name="line389"></a>  assertEquals(0, date.getUTCMilliseconds());
<a name="line390"></a>
<a name="line391"></a>  var date = goog.date.DateTime.fromRfc822String(&#39;&#39;);
<a name="line392"></a>  assertEquals(null, date);
<a name="line393"></a>
<a name="line394"></a>  var date = goog.date.DateTime.fromRfc822String(&#39;Invalid Date String&#39;);
<a name="line395"></a>  assertEquals(null, date);
<a name="line396"></a>
<a name="line397"></a>  var date = goog.date.DateTime.fromRfc822String(&#39;Sat, 02 Oct 2010&#39;);
<a name="line398"></a>  assertEquals(2010, date.getFullYear());
<a name="line399"></a>  assertEquals(9, date.getMonth());
<a name="line400"></a>  assertEquals(2, date.getDate());
<a name="line401"></a>  assertEquals(0, date.getHours());
<a name="line402"></a>  assertEquals(0, date.getMinutes());
<a name="line403"></a>  assertEquals(0, date.getSeconds());
<a name="line404"></a>  assertEquals(0, date.getMilliseconds());
<a name="line405"></a>  assertEquals(new Date(2010, 9, 2).getTime(), date.getTime());
<a name="line406"></a>}
<a name="line407"></a>
<a name="line408"></a>function testIsoStringToDate() {
<a name="line409"></a>  var iso = &#39;20060210T000000Z&#39;;
<a name="line410"></a>  var date = goog.date.fromIsoString(iso);
<a name="line411"></a>
<a name="line412"></a>  assertEquals(&#39;Got 2006 from &#39; + iso, 2006, date.getFullYear());
<a name="line413"></a>  assertEquals(&#39;Got February from &#39; + iso, 1, date.getMonth());
<a name="line414"></a>  // use getUTCDate() here, since in &#39;iso&#39; var we specified timezone
<a name="line415"></a>  // as being a zero offset from GMT
<a name="line416"></a>  assertEquals(&#39;Got 10th from &#39; + iso, 10, date.getUTCDate());
<a name="line417"></a>
<a name="line418"></a>  // YYYY-MM-DD
<a name="line419"></a>  iso = &#39;2005-02-22&#39;;
<a name="line420"></a>  date = goog.date.fromIsoString(iso);
<a name="line421"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line422"></a>  assertEquals(&#39;Got February from &#39; + iso, 1, date.getMonth());
<a name="line423"></a>  assertEquals(&#39;Got 22nd from &#39; + iso, 22, date.getDate());
<a name="line424"></a>
<a name="line425"></a>  // YYYYMMDD
<a name="line426"></a>  iso = &#39;20050222&#39;;
<a name="line427"></a>  date = goog.date.fromIsoString(iso);
<a name="line428"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line429"></a>  assertEquals(&#39;Got February from &#39; + iso, 1, date.getMonth());
<a name="line430"></a>  assertEquals(&#39;Got 22nd from &#39; + iso, 22, date.getDate());
<a name="line431"></a>
<a name="line432"></a>  // YYYY-MM
<a name="line433"></a>  iso = &#39;2005-08&#39;;
<a name="line434"></a>  date = goog.date.fromIsoString(iso);
<a name="line435"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line436"></a>  assertEquals(&#39;Got August from &#39; + iso, 7, date.getMonth());
<a name="line437"></a>
<a name="line438"></a>  // YYYYMM
<a name="line439"></a>  iso = &#39;200502&#39;;
<a name="line440"></a>  date = goog.date.fromIsoString(iso);
<a name="line441"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line442"></a>  assertEquals(&#39;Got February from &#39; + iso, 1, date.getMonth());
<a name="line443"></a>
<a name="line444"></a>  // YYYY
<a name="line445"></a>  iso = &#39;2005&#39;;
<a name="line446"></a>  date = goog.date.fromIsoString(iso);
<a name="line447"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line448"></a>
<a name="line449"></a>  // 1997-W01 or 1997W01
<a name="line450"></a>  iso = &#39;2005-W22&#39;;
<a name="line451"></a>  date = goog.date.fromIsoString(iso);
<a name="line452"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line453"></a>  assertEquals(&#39;Got May from &#39; + iso, 4, date.getMonth());
<a name="line454"></a>  assertEquals(&#39;Got 30th from &#39; + iso, 30, date.getDate());
<a name="line455"></a>
<a name="line456"></a>  iso = &#39;2005W22&#39;;
<a name="line457"></a>  date = goog.date.fromIsoString(iso);
<a name="line458"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line459"></a>  assertEquals(&#39;Got May from &#39; + iso, 4, date.getMonth());
<a name="line460"></a>  assertEquals(&#39;Got 30th from &#39; + iso, 30, date.getDate());
<a name="line461"></a>
<a name="line462"></a>  // 1997-W01-2 or 1997W012
<a name="line463"></a>  iso = &#39;2005-W22-4&#39;;
<a name="line464"></a>  date = goog.date.fromIsoString(iso);
<a name="line465"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line466"></a>  assertEquals(&#39;Got June from &#39; + iso, 5, date.getMonth());
<a name="line467"></a>  assertEquals(&#39;Got 2nd from &#39; + iso, 2, date.getDate());
<a name="line468"></a>
<a name="line469"></a>  iso = &#39;2005W224&#39;;
<a name="line470"></a>  date = goog.date.fromIsoString(iso);
<a name="line471"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line472"></a>  assertEquals(&#39;Got June from &#39; + iso, 5, date.getMonth());
<a name="line473"></a>  assertEquals(&#39;Got 2nd from &#39; + iso, 2, date.getDate());
<a name="line474"></a>
<a name="line475"></a>  iso = &#39;2004-W53-6&#39;;
<a name="line476"></a>  date = goog.date.fromIsoString(iso);
<a name="line477"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line478"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line479"></a>  assertEquals(&#39;Got 1st from &#39; + iso, 1, date.getDate());
<a name="line480"></a>
<a name="line481"></a>  iso = &#39;2004-W53-7&#39;;
<a name="line482"></a>  date = goog.date.fromIsoString(iso);
<a name="line483"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line484"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line485"></a>  assertEquals(&#39;Got 2nd from &#39; + iso, 2, date.getDate());
<a name="line486"></a>
<a name="line487"></a>  iso = &#39;2005-W52-6&#39;;
<a name="line488"></a>  date = goog.date.fromIsoString(iso);
<a name="line489"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line490"></a>  assertEquals(&#39;Got December from &#39; + iso, 11, date.getMonth());
<a name="line491"></a>  assertEquals(&#39;Got 31st from &#39; + iso, 31, date.getDate());
<a name="line492"></a>
<a name="line493"></a>  // both years 2007 start with the same day
<a name="line494"></a>  iso = &#39;2007-W01-1&#39;;
<a name="line495"></a>  date = goog.date.fromIsoString(iso);
<a name="line496"></a>  assertEquals(&#39;Got 2007 from &#39; + iso, 2007, date.getFullYear());
<a name="line497"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line498"></a>  assertEquals(&#39;Got 1st from &#39; + iso, 1, date.getDate());
<a name="line499"></a>
<a name="line500"></a>  iso = &#39;2007-W52-7&#39;;
<a name="line501"></a>  date = goog.date.fromIsoString(iso);
<a name="line502"></a>  assertEquals(&#39;Got 2007 from &#39; + iso, 2007, date.getFullYear());
<a name="line503"></a>  assertEquals(&#39;Got December from &#39; + iso, 11, date.getMonth());
<a name="line504"></a>  assertEquals(&#39;Got 30th from &#39; + iso, 30, date.getDate());
<a name="line505"></a>
<a name="line506"></a>  iso = &#39;2008-W01-1&#39;;
<a name="line507"></a>  date = goog.date.fromIsoString(iso);
<a name="line508"></a>  assertEquals(&#39;Got 2007 from &#39; + iso, 2007, date.getFullYear());
<a name="line509"></a>  assertEquals(&#39;Got December from &#39; + iso, 11, date.getMonth());
<a name="line510"></a>  assertEquals(&#39;Got 31st from &#39; + iso, 31, date.getDate());
<a name="line511"></a>
<a name="line512"></a>  // Gregorian year 2008 is a leap year,
<a name="line513"></a>  // ISO year 2008 is 2 days shorter:
<a name="line514"></a>  // 1 day longer at the start, 3 days shorter at the end
<a name="line515"></a>  iso = &#39;2008-W01-2&#39;;
<a name="line516"></a>  date = goog.date.fromIsoString(iso);
<a name="line517"></a>  assertEquals(&#39;Got 2008 from &#39; + iso, 2008, date.getFullYear());
<a name="line518"></a>  assertEquals(&#39;Got Jan from &#39; + iso, 0, date.getMonth());
<a name="line519"></a>  assertEquals(&#39;Got 1st from &#39; + iso, 1, date.getDate());
<a name="line520"></a>
<a name="line521"></a>  // ISO year is three days into the previous gregorian year
<a name="line522"></a>  iso = &#39;2009-W01-1&#39;;
<a name="line523"></a>  date = goog.date.fromIsoString(iso);
<a name="line524"></a>  assertEquals(&#39;Got 2008 from &#39; + iso, 2008, date.getFullYear());
<a name="line525"></a>  assertEquals(&#39;Got December from &#39; + iso, 11, date.getMonth());
<a name="line526"></a>  assertEquals(&#39;Got 29th from &#39; + iso, 29, date.getDate());
<a name="line527"></a>
<a name="line528"></a>  iso = &#39;2009-W01-3&#39;;
<a name="line529"></a>  date = goog.date.fromIsoString(iso);
<a name="line530"></a>  assertEquals(&#39;Got 2008 from &#39; + iso, 2008, date.getFullYear());
<a name="line531"></a>  assertEquals(&#39;Got December from &#39; + iso, 11, date.getMonth());
<a name="line532"></a>  assertEquals(&#39;Got 31st from &#39; + iso, 31, date.getDate());
<a name="line533"></a>
<a name="line534"></a>  iso = &#39;2009-W01-4&#39;;
<a name="line535"></a>  date = goog.date.fromIsoString(iso);
<a name="line536"></a>  assertEquals(&#39;Got 2009 from &#39; + iso, 2009, date.getFullYear());
<a name="line537"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line538"></a>  assertEquals(&#39;Got 1st from &#39; + iso, 1, date.getDate());
<a name="line539"></a>
<a name="line540"></a>  // ISO year is three days into the next gregorian year
<a name="line541"></a>  iso = &#39;2009-W53-4&#39;;
<a name="line542"></a>  date = goog.date.fromIsoString(iso);
<a name="line543"></a>  assertEquals(&#39;Got 2009 from &#39; + iso, 2009, date.getFullYear());
<a name="line544"></a>  assertEquals(&#39;Got December from &#39; + iso, 11, date.getMonth());
<a name="line545"></a>  assertEquals(&#39;Got 31st from &#39; + iso, 31, date.getDate());
<a name="line546"></a>
<a name="line547"></a>  iso = &#39;2009-W53-5&#39;;
<a name="line548"></a>  date = goog.date.fromIsoString(iso);
<a name="line549"></a>  assertEquals(&#39;Got 2010 from &#39; + iso, 2010, date.getFullYear());
<a name="line550"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line551"></a>  assertEquals(&#39;Got 1st from &#39; + iso, 1, date.getDate());
<a name="line552"></a>
<a name="line553"></a>  iso = &#39;2009-W53-6&#39;;
<a name="line554"></a>  date = goog.date.fromIsoString(iso);
<a name="line555"></a>  assertEquals(&#39;Got 2010 from &#39; + iso, 2010, date.getFullYear());
<a name="line556"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line557"></a>  assertEquals(&#39;Got 2nd from &#39; + iso, 2, date.getDate());
<a name="line558"></a>
<a name="line559"></a>  iso = &#39;2009-W53-7&#39;;
<a name="line560"></a>  date = goog.date.fromIsoString(iso);
<a name="line561"></a>  assertEquals(&#39;Got 2010 from &#39; + iso, 2010, date.getFullYear());
<a name="line562"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line563"></a>  assertEquals(&#39;Got 3rd from &#39; + iso, 3, date.getDate());
<a name="line564"></a>
<a name="line565"></a>  iso = &#39;2010-W01-1&#39;;
<a name="line566"></a>  date = goog.date.fromIsoString(iso);
<a name="line567"></a>  assertEquals(&#39;Got 2010 from &#39; + iso, 2010, date.getFullYear());
<a name="line568"></a>  assertEquals(&#39;Got January from &#39; + iso, 0, date.getMonth());
<a name="line569"></a>  assertEquals(&#39;Got 4th from &#39; + iso, 4, date.getDate());
<a name="line570"></a>
<a name="line571"></a>  // Examples where the ISO year is three days into the previous gregorian year
<a name="line572"></a>
<a name="line573"></a>  // 1995-035 or 1995035
<a name="line574"></a>  iso = &#39;2005-146&#39;;
<a name="line575"></a>  date = goog.date.fromIsoString(iso);
<a name="line576"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line577"></a>  assertEquals(&#39;Got May from &#39; + iso, 4, date.getMonth());
<a name="line578"></a>  assertEquals(&#39;Got 26th from &#39; + iso, 26, date.getDate());
<a name="line579"></a>
<a name="line580"></a>  iso = &#39;2005146&#39;;
<a name="line581"></a>  date = goog.date.fromIsoString(iso);
<a name="line582"></a>  assertEquals(&#39;Got 2005 from &#39; + iso, 2005, date.getFullYear());
<a name="line583"></a>  assertEquals(&#39;Got May from &#39; + iso, 4, date.getMonth());
<a name="line584"></a>  assertEquals(&#39;Got 26th from &#39; + iso, 26, date.getDate());
<a name="line585"></a>}
<a name="line586"></a>
<a name="line587"></a>
<a name="line588"></a>// test private function used by goog.date.Date.toIsoString()
<a name="line589"></a>function test_setIso8601TimeOnly_() {
<a name="line590"></a>  // 23:59:59
<a name="line591"></a>  var d = new goog.date.DateTime(0, 0);
<a name="line592"></a>  var iso = &#39;18:46:39&#39;;
<a name="line593"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line594"></a>  assertEquals(&#39;Got 18 hours from &#39; + iso, 18, d.getHours());
<a name="line595"></a>  assertEquals(&#39;Got 46 minutes from &#39; + iso, 46, d.getMinutes());
<a name="line596"></a>  assertEquals(&#39;Got 39 seconds from &#39; + iso, 39, d.getSeconds());
<a name="line597"></a>
<a name="line598"></a>  // 235959
<a name="line599"></a>  d = new goog.date.DateTime(0, 0);
<a name="line600"></a>  iso = &#39;184639&#39;;
<a name="line601"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line602"></a>  assertEquals(&#39;Got 18 hours from &#39; + iso, 18, d.getHours());
<a name="line603"></a>  assertEquals(&#39;Got 46 minutes from &#39; + iso, 46, d.getMinutes());
<a name="line604"></a>  assertEquals(&#39;Got 39 seconds from &#39; + iso, 39, d.getSeconds());
<a name="line605"></a>
<a name="line606"></a>  // 23:59, 2359, or 23
<a name="line607"></a>  d = new goog.date.DateTime(0, 0);
<a name="line608"></a>  iso = &#39;18:46&#39;;
<a name="line609"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line610"></a>  assertEquals(&#39;Got 18 hours from &#39; + iso, 18, d.getHours());
<a name="line611"></a>  assertEquals(&#39;Got 46 minutes from &#39; + iso, 46, d.getMinutes());
<a name="line612"></a>
<a name="line613"></a>  d = new goog.date.DateTime(0, 0);
<a name="line614"></a>  iso = &#39;1846&#39;;
<a name="line615"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line616"></a>  assertEquals(&#39;Got 18 hours from &#39; + iso, 18, d.getHours());
<a name="line617"></a>  assertEquals(&#39;Got 46 minutes from &#39; + iso, 46, d.getMinutes());
<a name="line618"></a>
<a name="line619"></a>  d = new goog.date.DateTime(0, 0);
<a name="line620"></a>  iso = &#39;18&#39;;
<a name="line621"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line622"></a>  assertEquals(&#39;Got 18 hours from &#39; + iso, 18, d.getHours());
<a name="line623"></a>
<a name="line624"></a>  d = new goog.date.DateTime(0, 0);
<a name="line625"></a>  iso = &#39;18463&#39;;
<a name="line626"></a>  assertFalse(&#39;failed to parse &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line627"></a>  assertTrue(&#39;date did not change&#39;, d.equals(new goog.date.DateTime(0, 0)));
<a name="line628"></a>
<a name="line629"></a>  // 23:59:59.9942 or 235959.9942
<a name="line630"></a>  d = new goog.date.DateTime(0, 0);
<a name="line631"></a>  iso = &#39;18:46:39.9942&#39;;
<a name="line632"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line633"></a>  assertEquals(&#39;Got 18 hours from &#39; + iso, 18, d.getHours());
<a name="line634"></a>  assertEquals(&#39;Got 46 minutes from &#39; + iso, 46, d.getMinutes());
<a name="line635"></a>  assertEquals(&#39;Got 39 seconds from &#39; + iso, 39, d.getSeconds());
<a name="line636"></a>
<a name="line637"></a>  // Fails in Safari4 Winxp, temporarily disabled
<a name="line638"></a>  expectedFailures.expectFailureFor(isWinxpSafari4());
<a name="line639"></a>  try {
<a name="line640"></a>    if (goog.userAgent.WEBKIT &amp;&amp; goog.userAgent.MAC) {
<a name="line641"></a>      // Both Safari 3.1 and WebKit (on Mac) return floating-point values.
<a name="line642"></a>      assertRoughlyEquals(&#39;Got roughly 994.2 milliseconds from &#39; + iso, 994.2,
<a name="line643"></a>          d.getMilliseconds(), 0.01);
<a name="line644"></a>    } else {
<a name="line645"></a>      // Other browsers, including WebKit on Windows, return integers.
<a name="line646"></a>      assertEquals(
<a name="line647"></a>          &#39;Got 994 milliseconds from &#39; + iso, 994, d.getMilliseconds());
<a name="line648"></a>    }
<a name="line649"></a>
<a name="line650"></a>    d = new goog.date.DateTime(0, 0);
<a name="line651"></a>    iso = &#39;184639.9942&#39;;
<a name="line652"></a>    assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line653"></a>    assertEquals(&#39;Got 18 hours from &#39; + iso, 18, d.getHours());
<a name="line654"></a>    assertEquals(&#39;Got 46 minutes from &#39; + iso, 46, d.getMinutes());
<a name="line655"></a>    assertEquals(&#39;Got 39 seconds from &#39; + iso, 39, d.getSeconds());
<a name="line656"></a>    if (goog.userAgent.WEBKIT &amp;&amp; goog.userAgent.MAC) {
<a name="line657"></a>      // Both Safari 3.1 and WebKit (on Mac) return floating-point values.
<a name="line658"></a>      assertRoughlyEquals(&#39;Got roughly 994.2 milliseconds from &#39; + iso, 994.2,
<a name="line659"></a>          d.getMilliseconds(), 0.01);
<a name="line660"></a>    } else {
<a name="line661"></a>      // Other browsers, including WebKit on Windows, return integers.
<a name="line662"></a>      assertEquals(
<a name="line663"></a>          &#39;Got 994 milliseconds from &#39; + iso, 994, d.getMilliseconds());
<a name="line664"></a>    }
<a name="line665"></a>  } catch (e) {
<a name="line666"></a>    expectedFailures.handleException(e);
<a name="line667"></a>  }
<a name="line668"></a>
<a name="line669"></a>
<a name="line670"></a>  // 1995-02-04 24:00 = 1995-02-05 00:00
<a name="line671"></a>  // timezone tests
<a name="line672"></a>  var offset = new Date().getTimezoneOffset() / 60;
<a name="line673"></a>  d = new goog.date.DateTime(0, 0);
<a name="line674"></a>  iso = &#39;18:46:39+07:00&#39;;
<a name="line675"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line676"></a>  assertEquals(&#39;Got an 11-hour GMT offset from &#39; + iso, 11, d.getUTCHours());
<a name="line677"></a>
<a name="line678"></a>  d = new goog.date.DateTime(0, 0);
<a name="line679"></a>  iso = &#39;18:46:39+00:00&#39;;
<a name="line680"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line681"></a>  assertEquals(&#39;Got an 18-hour GMT offset from &#39; + iso, 18, d.getUTCHours());
<a name="line682"></a>
<a name="line683"></a>  d = new goog.date.DateTime(0, 0);
<a name="line684"></a>  iso = &#39;16:46:39-07:00&#39;;
<a name="line685"></a>  assertTrue(&#39;parsed &#39; + iso, goog.date.setIso8601TimeOnly_(d, iso));
<a name="line686"></a>  assertEquals(&#39;Got a 23-hour GMT offset from &#39; + iso, 23, d.getUTCHours());
<a name="line687"></a>}
<a name="line688"></a>
<a name="line689"></a>
<a name="line690"></a>function testDateIntervalAdd() {
<a name="line691"></a>  // -1m, cross year boundary
<a name="line692"></a>  var d = new goog.date.Date(2007, goog.date.month.JAN, 1);
<a name="line693"></a>  d.add(new goog.date.Interval(goog.date.Interval.MONTHS, -1));
<a name="line694"></a>  assertEquals(&#39;2007-01-01 - 1m = 2006-12-01&#39;, &#39;20061201&#39;, d.toIsoString());
<a name="line695"></a>
<a name="line696"></a>  // +1y2m3d
<a name="line697"></a>  d = new goog.date.Date(2006, goog.date.month.JAN, 1);
<a name="line698"></a>  d.add(new goog.date.Interval(1, 2, 3));
<a name="line699"></a>  assertEquals(&#39;2006-01-01 + 1y2m3d = 2007-03-04&#39;, &#39;20070304&#39;, d.toIsoString());
<a name="line700"></a>
<a name="line701"></a>  // -1y2m3d (negative interval)
<a name="line702"></a>  d = new goog.date.Date(2007, goog.date.month.MAR, 4);
<a name="line703"></a>  d.add(new goog.date.Interval(-1, -2, -3));
<a name="line704"></a>  assertEquals(&#39;2007-03-04 - 1y2m3d = 2006-01-01&#39;, &#39;20060101&#39;, d.toIsoString());
<a name="line705"></a>
<a name="line706"></a>  // 2007-12-30 + 3d (roll over to next year)
<a name="line707"></a>  d = new goog.date.Date(2007, goog.date.month.DEC, 30);
<a name="line708"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 3));
<a name="line709"></a>  assertEquals(&#39;2007-12-30 + 3d = 2008-01-02&#39;, &#39;20080102&#39;, d.toIsoString());
<a name="line710"></a>
<a name="line711"></a>  // 2004-03-01 - 1d (handle leap year)
<a name="line712"></a>  d = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line713"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, -1));
<a name="line714"></a>  assertEquals(&#39;2004-03-01 - 1d = 2004-02-29&#39;, &#39;20040229&#39;, d.toIsoString());
<a name="line715"></a>
<a name="line716"></a>  // 2004-02-29 + 1y (stays at end of Feb, doesn&#39;t roll to Mar)
<a name="line717"></a>  d = new goog.date.Date(2004, goog.date.month.FEB, 29);
<a name="line718"></a>  d.add(new goog.date.Interval(goog.date.Interval.YEARS, 1));
<a name="line719"></a>  assertEquals(&#39;2004-02-29 + 1y = 2005-02-28&#39;, &#39;20050228&#39;, d.toIsoString());
<a name="line720"></a>
<a name="line721"></a>  // 2004-02-29 - 1y (stays at end of Feb, doesn&#39;t roll to Mar)
<a name="line722"></a>  d = new goog.date.Date(2004, goog.date.month.FEB, 29);
<a name="line723"></a>  d.add(new goog.date.Interval(goog.date.Interval.YEARS, -1));
<a name="line724"></a>  assertEquals(&#39;2004-02-29 - 1y = 2003-02-28&#39;, &#39;20030228&#39;, d.toIsoString());
<a name="line725"></a>
<a name="line726"></a>  // 2003-02-28 + 1y (stays at 28, doesn&#39;t go to leap year end of Feb)
<a name="line727"></a>  d = new goog.date.Date(2003, goog.date.month.FEB, 28);
<a name="line728"></a>  d.add(new goog.date.Interval(goog.date.Interval.YEARS, 1));
<a name="line729"></a>  assertEquals(&#39;2003-02-28 + 1y = 2004-02-28&#39;, &#39;20040228&#39;, d.toIsoString());
<a name="line730"></a>
<a name="line731"></a>  // 2005-02-28 - 1y (stays at 28, doesn&#39;t go to leap year end of Feb)
<a name="line732"></a>  d = new goog.date.Date(2005, goog.date.month.FEB, 28);
<a name="line733"></a>  d.add(new goog.date.Interval(goog.date.Interval.YEARS, -1));
<a name="line734"></a>  assertEquals(&#39;2005-02-28 - 1y = 2004-02-28&#39;, &#39;20040228&#39;, d.toIsoString());
<a name="line735"></a>
<a name="line736"></a>  // 2003-01-31 + 1y (stays at end of Jan, standard case)
<a name="line737"></a>  d = new goog.date.Date(2003, goog.date.month.JAN, 31);
<a name="line738"></a>  d.add(new goog.date.Interval(goog.date.Interval.YEARS, 1));
<a name="line739"></a>  assertEquals(&#39;2003-01-31 + 1y = 2004-01-31&#39;, &#39;20040131&#39;, d.toIsoString());
<a name="line740"></a>
<a name="line741"></a>  // 2005-01-31 - 1y (stays at end of Jan, standard case)
<a name="line742"></a>  d = new goog.date.Date(2005, goog.date.month.JAN, 31);
<a name="line743"></a>  d.add(new goog.date.Interval(goog.date.Interval.YEARS, -1));
<a name="line744"></a>  assertEquals(&#39;2005-01-31 - 1y = 2004-01-31&#39;, &#39;20040131&#39;, d.toIsoString());
<a name="line745"></a>
<a name="line746"></a>  // 2006-01-31 + 1m (stays at end of Feb, doesn&#39;t roll to Mar, non-leap-year)
<a name="line747"></a>  d = new goog.date.Date(2006, goog.date.month.JAN, 31);
<a name="line748"></a>  d.add(new goog.date.Interval(goog.date.Interval.MONTHS, 1));
<a name="line749"></a>  assertEquals(&#39;2006-01-31 + 1m = 2006-02-28&#39;, &#39;20060228&#39;, d.toIsoString());
<a name="line750"></a>
<a name="line751"></a>  // 2004-02-29 + 1m (stays at 29, standard case)
<a name="line752"></a>  d = new goog.date.Date(2004, goog.date.month.FEB, 29);
<a name="line753"></a>  d.add(new goog.date.Interval(goog.date.Interval.MONTHS, +1));
<a name="line754"></a>  assertEquals(&#39;2004-02-29 + 1m = 2004-03-29&#39;, &#39;20040329&#39;, d.toIsoString());
<a name="line755"></a>
<a name="line756"></a>  // 2004-02-29 - 1m (stays at 29, standard case)
<a name="line757"></a>  d = new goog.date.Date(2004, goog.date.month.FEB, 29);
<a name="line758"></a>  d.add(new goog.date.Interval(goog.date.Interval.MONTHS, -1));
<a name="line759"></a>  assertEquals(&#39;2004-02-29 - 1m = 2004-01-29&#39;, &#39;20040129&#39;, d.toIsoString());
<a name="line760"></a>
<a name="line761"></a>  // 2004-01-30 + 1m (snaps to Feb 29)
<a name="line762"></a>  d = new goog.date.Date(2004, goog.date.month.JAN, 30);
<a name="line763"></a>  d.add(new goog.date.Interval(goog.date.Interval.MONTHS, 1));
<a name="line764"></a>  assertEquals(&#39;2004-01-30 + 1m = 2004-02-29&#39;, &#39;20040229&#39;, d.toIsoString());
<a name="line765"></a>
<a name="line766"></a>  // 2004-03-30 - 1m (snaps to Feb 29)
<a name="line767"></a>  d = new goog.date.Date(2004, goog.date.month.MAR, 30);
<a name="line768"></a>  d.add(new goog.date.Interval(goog.date.Interval.MONTHS, -1));
<a name="line769"></a>  assertEquals(&#39;2004-03-30 - 1m = 2004-02-29&#39;, &#39;20040229&#39;, d.toIsoString());
<a name="line770"></a>
<a name="line771"></a>  // 2004-03-30 + 1m (stays at 30, standard case)
<a name="line772"></a>  d = new goog.date.Date(2004, goog.date.month.MAR, 30);
<a name="line773"></a>  d.add(new goog.date.Interval(goog.date.Interval.MONTHS, 1));
<a name="line774"></a>  assertEquals(&#39;2004-03-30 + 1m = 2004-04-30&#39;, &#39;20040430&#39;, d.toIsoString());
<a name="line775"></a>
<a name="line776"></a>  // 2008-10-30 + 1d (roll over to 31).
<a name="line777"></a>  d = new goog.date.Date(2008, goog.date.month.OCT, 30);
<a name="line778"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line779"></a>  assertEquals(&#39;2008-10-30 + 1d = 2008-10-31&#39;, &#39;20081031&#39;, d.toIsoString());
<a name="line780"></a>
<a name="line781"></a>  // 2008-10-31 + 1d (roll over to November, not December).
<a name="line782"></a>  d = new goog.date.Date(2008, goog.date.month.OCT, 31);
<a name="line783"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line784"></a>  assertEquals(&#39;2008-10-31 + 1d = 2008-11-01&#39;, &#39;20081101&#39;, d.toIsoString());
<a name="line785"></a>
<a name="line786"></a>  // 2008-10-17 + 1d (Brasilia dst).
<a name="line787"></a>  d = new goog.date.Date(2008, goog.date.month.OCT, 17);
<a name="line788"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line789"></a>  assertEquals(&#39;2008-10-17 + 1d = 2008-10-18&#39;, &#39;20081018&#39;, d.toIsoString());
<a name="line790"></a>
<a name="line791"></a>  // 2008-10-18 + 1d (Brasilia dst).
<a name="line792"></a>  d = new goog.date.Date(2008, goog.date.month.OCT, 18);
<a name="line793"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line794"></a>  assertEquals(&#39;2008-10-18 + 1d = 2008-10-19&#39;, &#39;20081019&#39;, d.toIsoString());
<a name="line795"></a>
<a name="line796"></a>  // 2008-10-19 + 1d (Brasilia dst).
<a name="line797"></a>  d = new goog.date.Date(2008, goog.date.month.OCT, 19);
<a name="line798"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line799"></a>  assertEquals(&#39;2008-10-19 + 1d = 2008-10-20&#39;, &#39;20081020&#39;, d.toIsoString());
<a name="line800"></a>
<a name="line801"></a>  // 2008-02-16 + 1d (Brasilia dst).
<a name="line802"></a>  d = new goog.date.Date(2008, goog.date.month.FEB, 16);
<a name="line803"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line804"></a>  assertEquals(&#39;2008-02-16 + 1d = 2008-02-17&#39;, &#39;20080217&#39;, d.toIsoString());
<a name="line805"></a>
<a name="line806"></a>  // 2008-02-17 + 1d (Brasilia dst).
<a name="line807"></a>  d = new goog.date.Date(2008, goog.date.month.FEB, 17);
<a name="line808"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line809"></a>  assertEquals(&#39;2008-02-17 + 1d = 2008-02-18&#39;, &#39;20080218&#39;, d.toIsoString());
<a name="line810"></a>}
<a name="line811"></a>
<a name="line812"></a>
<a name="line813"></a>function testDateEquals() {
<a name="line814"></a>  var d1 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line815"></a>  var d2 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line816"></a>  assertFalse(&#39;d1 != null&#39;, d1.equals(null));
<a name="line817"></a>  assertFalse(&#39;d2 != undefined&#39;, d2.equals(undefined));
<a name="line818"></a>  assertTrue(&#39;d1 == d2&#39;, d1.equals(d2));
<a name="line819"></a>  assertTrue(&#39;d2 == d1&#39;, d2.equals(d1));
<a name="line820"></a>
<a name="line821"></a>  d1 = new goog.date.Date(2005, goog.date.month.MAR, 1);
<a name="line822"></a>  d2 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line823"></a>  assertFalse(&#39;different year&#39;, d1.equals(d2));
<a name="line824"></a>
<a name="line825"></a>  d1 = new goog.date.Date(2004, goog.date.month.FEB, 1);
<a name="line826"></a>  d2 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line827"></a>  assertFalse(&#39;different month&#39;, d1.equals(d2));
<a name="line828"></a>
<a name="line829"></a>  d1 = new goog.date.Date(2004, goog.date.month.MAR, 2);
<a name="line830"></a>  d2 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line831"></a>  assertFalse(&#39;different date&#39;, d1.equals(d2));
<a name="line832"></a>
<a name="line833"></a>  // try passing in DateTime, time fields should be ignored
<a name="line834"></a>  d1 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line835"></a>  d2 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30);
<a name="line836"></a>  assertTrue(&#39;using goog.date.DateTime, same date&#39;, d1.equals(d2));
<a name="line837"></a>}
<a name="line838"></a>
<a name="line839"></a>
<a name="line840"></a>function testDateTimeConstructor() {
<a name="line841"></a>  var date = new goog.date.DateTime(2001, 2, 3, 4, 5, 6, 7);
<a name="line842"></a>  assertEquals(2001, date.getFullYear());
<a name="line843"></a>  assertEquals(2, date.getMonth());
<a name="line844"></a>  assertEquals(3, date.getDate());
<a name="line845"></a>  assertEquals(4, date.getHours());
<a name="line846"></a>  assertEquals(5, date.getMinutes());
<a name="line847"></a>  assertEquals(6, date.getSeconds());
<a name="line848"></a>  assertEquals(7, date.getMilliseconds());
<a name="line849"></a>  assertEquals(new Date(2001, 2, 3, 4, 5, 6, 7).getTime(), date.getTime());
<a name="line850"></a>
<a name="line851"></a>  var date = new goog.date.DateTime(2001);
<a name="line852"></a>  assertEquals(2001, date.getFullYear());
<a name="line853"></a>  assertEquals(0, date.getMonth());
<a name="line854"></a>  assertEquals(1, date.getDate());
<a name="line855"></a>  assertEquals(0, date.getHours());
<a name="line856"></a>  assertEquals(0, date.getMinutes());
<a name="line857"></a>  assertEquals(0, date.getSeconds());
<a name="line858"></a>  assertEquals(0, date.getMilliseconds());
<a name="line859"></a>
<a name="line860"></a>  var date = new goog.date.DateTime(new Date(2001, 2, 3, 4, 5, 6, 7));
<a name="line861"></a>  assertEquals(2001, date.getFullYear());
<a name="line862"></a>  assertEquals(2, date.getMonth());
<a name="line863"></a>  assertEquals(3, date.getDate());
<a name="line864"></a>  assertEquals(4, date.getHours());
<a name="line865"></a>  assertEquals(5, date.getMinutes());
<a name="line866"></a>  assertEquals(6, date.getSeconds());
<a name="line867"></a>  assertEquals(7, date.getMilliseconds());
<a name="line868"></a>  assertEquals(new Date(2001, 2, 3, 4, 5, 6, 7).getTime(), date.getTime());
<a name="line869"></a>
<a name="line870"></a>  goog.now = function() {
<a name="line871"></a>    return new Date(2001, 2, 3, 4).getTime();
<a name="line872"></a>  };
<a name="line873"></a>  var date = new goog.date.DateTime();
<a name="line874"></a>  assertEquals(2001, date.getFullYear());
<a name="line875"></a>  assertEquals(2, date.getMonth());
<a name="line876"></a>  assertEquals(3, date.getDate());
<a name="line877"></a>  assertEquals(4, date.getHours());
<a name="line878"></a>  assertEquals(0, date.getMinutes());
<a name="line879"></a>  assertEquals(0, date.getSeconds());
<a name="line880"></a>  assertEquals(0, date.getMilliseconds());
<a name="line881"></a>  assertEquals(new Date(2001, 2, 3, 4).getTime(), date.getTime());
<a name="line882"></a>
<a name="line883"></a>  var date = new goog.date.DateTime(new Date(&#39;October 2, 2002 8:00:00&#39;));
<a name="line884"></a>  assertEquals(2002, date.getFullYear());
<a name="line885"></a>  assertEquals(9, date.getMonth());
<a name="line886"></a>  assertEquals(2, date.getDate());
<a name="line887"></a>  assertEquals(8, date.getHours());
<a name="line888"></a>  assertEquals(0, date.getMinutes());
<a name="line889"></a>  assertEquals(0, date.getSeconds());
<a name="line890"></a>  assertEquals(0, date.getMilliseconds());
<a name="line891"></a>  assertEquals(new Date(2002, 9, 2, 8).getTime(), date.getTime());
<a name="line892"></a>}
<a name="line893"></a>
<a name="line894"></a>
<a name="line895"></a>function testDateTimeEquals() {
<a name="line896"></a>  var d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30);
<a name="line897"></a>  var d2 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30);
<a name="line898"></a>  assertTrue(&#39;d1 == d2&#39;, d1.equals(d2));
<a name="line899"></a>  assertTrue(&#39;d2 == d1&#39;, d2.equals(d1));
<a name="line900"></a>
<a name="line901"></a>  d1 = new goog.date.DateTime(2007, goog.date.month.JAN, 1);
<a name="line902"></a>  d2 = new goog.date.DateTime(); // today
<a name="line903"></a>  assertFalse(&#39;different date&#39;, d1.equals(d2));
<a name="line904"></a>
<a name="line905"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1);
<a name="line906"></a>  d2 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12);
<a name="line907"></a>  assertFalse(&#39;different hours&#39;, d1.equals(d2));
<a name="line908"></a>
<a name="line909"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 29, 30);
<a name="line910"></a>  d2 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30);
<a name="line911"></a>  assertFalse(&#39;different minutes&#39;, d1.equals(d2));
<a name="line912"></a>
<a name="line913"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 29);
<a name="line914"></a>  d2 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30);
<a name="line915"></a>  assertFalse(&#39;different seconds&#39;, d1.equals(d2));
<a name="line916"></a>
<a name="line917"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30, 500);
<a name="line918"></a>  d2 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30, 500);
<a name="line919"></a>  assertTrue(&#39;same milliseconds&#39;, d1.equals(d2));
<a name="line920"></a>
<a name="line921"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30, 499);
<a name="line922"></a>  d2 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30, 500);
<a name="line923"></a>  assertFalse(&#39;different milliseconds&#39;, d1.equals(d2));
<a name="line924"></a>
<a name="line925"></a>  // try milliseconds again, this time comparing against a native Date
<a name="line926"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30);
<a name="line927"></a>  d2 = new Date(2004, 2, 1, 12, 30, 30, 999);
<a name="line928"></a>  assertFalse(&#39;different milliseconds, native Date&#39;, d1.equals(d2));
<a name="line929"></a>
<a name="line930"></a>  // pass in a goog.date.Date rather than a goog.date.DateTime
<a name="line931"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 12, 30, 30);
<a name="line932"></a>  d2 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line933"></a>  assertFalse(&#39;using goog.date.Date, different times&#39;, d1.equals(d2));
<a name="line934"></a>
<a name="line935"></a>  d1 = new goog.date.DateTime(2004, goog.date.month.MAR, 1, 0, 0, 0);
<a name="line936"></a>  d2 = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line937"></a>  assertTrue(&#39;using goog.date.Date, same time (midnight)&#39;, d1.equals(d2));
<a name="line938"></a>}
<a name="line939"></a>
<a name="line940"></a>
<a name="line941"></a>function testIntervalIsZero() {
<a name="line942"></a>  assertTrue(&#39;zero interval&#39;, new goog.date.Interval().isZero());
<a name="line943"></a>  var i = new goog.date.Interval(0, 0, 1, -24, 0, 0);
<a name="line944"></a>  assertFalse(&#39;1 day minus 24 hours is not considered zero&#39;, i.isZero());
<a name="line945"></a>}
<a name="line946"></a>
<a name="line947"></a>
<a name="line948"></a>function testIntervalGetInverse() {
<a name="line949"></a>  var i1 = new goog.date.Interval(goog.date.Interval.DAYS, -1);
<a name="line950"></a>  var i2 = i1.getInverse();
<a name="line951"></a>
<a name="line952"></a>  var d = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line953"></a>  d.add(i1);
<a name="line954"></a>  d.add(i2);
<a name="line955"></a>  var label = &#39;2004-03-01 - 1d + 1d = 2004-03-01&#39;;
<a name="line956"></a>  assertEquals(label, d.toIsoString(), &#39;20040301&#39;);
<a name="line957"></a>
<a name="line958"></a>  i1 = new goog.date.Interval(1, 2, 3);
<a name="line959"></a>  i2 = i1.getInverse();
<a name="line960"></a>
<a name="line961"></a>  d = new goog.date.Date(2004, goog.date.month.MAR, 1);
<a name="line962"></a>  d.add(i1);
<a name="line963"></a>  d.add(i2);
<a name="line964"></a>  label = &#39;2004-03-01 - 1y2m3d + 1y2m3d = 2004-03-01&#39;;
<a name="line965"></a>  assertEquals(label, d.toIsoString(), &#39;20040301&#39;);
<a name="line966"></a>}
<a name="line967"></a>
<a name="line968"></a>
<a name="line969"></a>function testIntervalTimes() {
<a name="line970"></a>  var i = new goog.date.Interval(1, 2, 3, 4, 5, 6);
<a name="line971"></a>  var expected = new goog.date.Interval(2, 4, 6, 8, 10, 12);
<a name="line972"></a>  assertTrue(&#39;double interval&#39;, expected.equals(i.times(2)));
<a name="line973"></a>}
<a name="line974"></a>
<a name="line975"></a>
<a name="line976"></a>//=== tests for goog.date.Interval.equals() ===
<a name="line977"></a>function testIntervalEquals() {
<a name="line978"></a>  var i1 = new goog.date.Interval(goog.date.Interval.DAYS, -1);
<a name="line979"></a>  var i2 = new goog.date.Interval(goog.date.Interval.DAYS, -1);
<a name="line980"></a>  assertTrue(&#39;-1d == -1d, aka i1 == i2&#39;, i1.equals(i2));
<a name="line981"></a>  assertTrue(&#39;-1d == -1d, aka i2 == i1&#39;, i2.equals(i1));
<a name="line982"></a>
<a name="line983"></a>  i1 = new goog.date.Interval(goog.date.Interval.DAYS, -1);
<a name="line984"></a>  i2 = new goog.date.Interval(goog.date.Interval.DAYS, 1);
<a name="line985"></a>  assertFalse(&#39;-1d != +1d, aka i1 == i2&#39;, i1.equals(i2));
<a name="line986"></a>  assertFalse(&#39;-1d != +1d, aka i2 == i1&#39;, i2.equals(i1));
<a name="line987"></a>
<a name="line988"></a>  i1 = new goog.date.Interval(0, 3); // Three months
<a name="line989"></a>  i2 = new goog.date.Interval(goog.date.Interval.MONTHS, 3);
<a name="line990"></a>  assertTrue(&#39;3m == 3m, aka i1 == i2&#39;, i1.equals(i2));
<a name="line991"></a>  assertTrue(&#39;3m == 3m, aka i2 == i1&#39;, i2.equals(i1));
<a name="line992"></a>
<a name="line993"></a>  //1 year, 6 months, 15 days, 12 hours, 30 minutes, 30 seconds
<a name="line994"></a>  i1 = new goog.date.Interval(1, 6, 15, 12, 30, 30);
<a name="line995"></a>  i2 = new goog.date.Interval(1, 6, 15, 12, 30, 30);
<a name="line996"></a>  assertTrue(&#39;1y6m15d12h30M30s == 1y6m15d12h30M30s&#39;, i1.equals(i2));
<a name="line997"></a>  assertTrue(&#39;1y6m15d12h30M30s == 1y6m15d12h30M30s&#39;, i2.equals(i1));
<a name="line998"></a>}
<a name="line999"></a>
<a name="line1000"></a>
<a name="line1001"></a>//=== tests for adding two goog.date.Interval intervals ===
<a name="line1002"></a>function testIntervalIntervalAdd() {
<a name="line1003"></a>  var i1 = new goog.date.Interval(1, 6, 15, 12, 30, 30);
<a name="line1004"></a>  var i2 = new goog.date.Interval(0, 3, 20, 10, 50, -25);
<a name="line1005"></a>  i1.add(i2);
<a name="line1006"></a>  assertTrue(&#39;i1 + i2&#39;, i1.equals(new goog.date.Interval(1, 9, 35, 22, 80, 5)));
<a name="line1007"></a>
<a name="line1008"></a>  i1 = new goog.date.Interval(1, 6, 15, 12, 30, 30);
<a name="line1009"></a>  i2 = new goog.date.Interval(0, 3, 20, 10, 50, -25);
<a name="line1010"></a>  i2.add(i1);
<a name="line1011"></a>  assertTrue(&#39;i2 + i1&#39;, i2.equals(new goog.date.Interval(1, 9, 35, 22, 80, 5)));
<a name="line1012"></a>
<a name="line1013"></a>  i1 = new goog.date.Interval(1, 6, 15, 12, 30, 30);
<a name="line1014"></a>  i2 = i1.getInverse();
<a name="line1015"></a>  i1.add(i2);
<a name="line1016"></a>  assertTrue(&#39;i1 + (-i1)&#39;, i1.equals(new goog.date.Interval()));
<a name="line1017"></a>
<a name="line1018"></a>  i1 = new goog.date.Interval(goog.date.Interval.DAYS, 1);
<a name="line1019"></a>  i2 = new goog.date.Interval(0, -2, -2);
<a name="line1020"></a>  i1.add(i2);
<a name="line1021"></a>  assertTrue(&#39;1d + (-2m-2d)&#39;, i1.equals(new goog.date.Interval(0, -2, -1)));
<a name="line1022"></a>}
<a name="line1023"></a>
<a name="line1024"></a>
<a name="line1025"></a>//=== tests conversion to and from ISO 8601 duration string ===
<a name="line1026"></a>function testIsoDuration() {
<a name="line1027"></a>  var interval1 = new goog.date.Interval(123, 456, 678, 11, 12, 455.5);
<a name="line1028"></a>  var duration1 = &#39;P123Y456M678DT11H12M455.5S&#39;;
<a name="line1029"></a>  assertTrue(&#39;parse full duration&#39;,
<a name="line1030"></a>      interval1.equals(goog.date.Interval.fromIsoString(duration1)));
<a name="line1031"></a>  assertEquals(&#39;create full duration&#39;, duration1, interval1.toIsoString());
<a name="line1032"></a>
<a name="line1033"></a>  var interval2 = new goog.date.Interval(123);
<a name="line1034"></a>  var duration2 = &#39;P123Y&#39;;
<a name="line1035"></a>  var duration2v = &#39;P123Y0M0DT0H0M0S&#39;;
<a name="line1036"></a>  assertTrue(&#39;parse year&#39;,
<a name="line1037"></a>      interval2.equals(goog.date.Interval.fromIsoString(duration2)));
<a name="line1038"></a>  assertEquals(&#39;create year&#39;, duration2, interval2.toIsoString());
<a name="line1039"></a>  assertEquals(&#39;create year, verbose&#39;, duration2v, interval2.toIsoString(true));
<a name="line1040"></a>
<a name="line1041"></a>  var interval3 = new goog.date.Interval(0, 0, 0, 11, 12, 40);
<a name="line1042"></a>  var duration3 = &#39;PT11H12M40S&#39;;
<a name="line1043"></a>  var duration3v = &#39;P0Y0M0DT11H12M40S&#39;;
<a name="line1044"></a>  assertTrue(&#39;parse time duration&#39;,
<a name="line1045"></a>      interval3.equals(goog.date.Interval.fromIsoString(duration3)));
<a name="line1046"></a>  assertEquals(&#39;create time duration&#39;, duration3, interval3.toIsoString());
<a name="line1047"></a>  assertEquals(&#39;create time duration, verbove&#39;,
<a name="line1048"></a>      duration3v, interval3.toIsoString(true));
<a name="line1049"></a>
<a name="line1050"></a>  var interval4 = new goog.date.Interval(7, 8, 9, 1, 2, 4);
<a name="line1051"></a>  var duration4 = &#39;P7Y8M9DT1H2M4S&#39;;
<a name="line1052"></a>  assertTrue(&#39;parse one-digit duration&#39;,
<a name="line1053"></a>      interval4.equals(goog.date.Interval.fromIsoString(duration4)));
<a name="line1054"></a>  assertEquals(&#39;create one-digit duration&#39;, duration4, interval4.toIsoString());
<a name="line1055"></a>
<a name="line1056"></a>  var interval5 = new goog.date.Interval(-123, -456, -678, -11, -12, -455.5);
<a name="line1057"></a>  var duration5 = &#39;-P123Y456M678DT11H12M455.5S&#39;;
<a name="line1058"></a>  assertTrue(&#39;parse full negative duration&#39;,
<a name="line1059"></a>      interval5.equals(goog.date.Interval.fromIsoString(duration5)));
<a name="line1060"></a>  assertEquals(&#39;create full negative duration&#39;,
<a name="line1061"></a>      duration5, interval5.toIsoString());
<a name="line1062"></a>
<a name="line1063"></a>  var interval6 = new goog.date.Interval(0, 0, -1);
<a name="line1064"></a>  var duration6 = &#39;-P1D&#39;;
<a name="line1065"></a>  var duration6v = &#39;-P0Y0M1DT0H0M0S&#39;;
<a name="line1066"></a>  assertTrue(&#39;parse partial negative duration&#39;,
<a name="line1067"></a>      interval6.equals(goog.date.Interval.fromIsoString(duration6)));
<a name="line1068"></a>  assertEquals(&#39;create partial negative duration&#39;,
<a name="line1069"></a>      duration6, interval6.toIsoString());
<a name="line1070"></a>  assertEquals(&#39;create partial negative duration, verbose&#39;,
<a name="line1071"></a>      duration6v, interval6.toIsoString(true));
<a name="line1072"></a>
<a name="line1073"></a>  var interval7 = new goog.date.Interval(0, 0, 9, 0, 0, 4);
<a name="line1074"></a>  var duration7 = &#39;P9DT4S&#39;;
<a name="line1075"></a>  var duration7v = &#39;P0Y0M9DT0H0M4S&#39;;
<a name="line1076"></a>  assertTrue(&#39;parse partial one-digit duration&#39;,
<a name="line1077"></a>      interval7.equals(goog.date.Interval.fromIsoString(duration7)));
<a name="line1078"></a>  assertTrue(&#39;parse partial one-digit duration, verbose&#39;,
<a name="line1079"></a>      interval7.equals(goog.date.Interval.fromIsoString(duration7v)));
<a name="line1080"></a>  assertEquals(&#39;create partial one-digit duration&#39;,
<a name="line1081"></a>      duration7, interval7.toIsoString());
<a name="line1082"></a>  assertEquals(&#39;create partial one-digit duration, verbose&#39;,
<a name="line1083"></a>      duration7v, interval7.toIsoString(true));
<a name="line1084"></a>
<a name="line1085"></a>  var interval8 = new goog.date.Interval(1, -1, 1, -1, 1, -1);
<a name="line1086"></a>  assertNull(&#39;create mixed sign duration&#39;, interval8.toIsoString());
<a name="line1087"></a>
<a name="line1088"></a>  var duration9 = &#39;1Y1M1DT1H1M1S&#39;;
<a name="line1089"></a>  assertNull(&#39;missing P&#39;, goog.date.Interval.fromIsoString(duration9));
<a name="line1090"></a>
<a name="line1091"></a>  var duration10 = &#39;P1Y1M1D1H1M1S&#39;;
<a name="line1092"></a>  assertNull(&#39;missing T&#39;, goog.date.Interval.fromIsoString(duration10));
<a name="line1093"></a>
<a name="line1094"></a>  var duration11 = &#39;P1Y1M1DT&#39;;
<a name="line1095"></a>  assertNull(&#39;extra T&#39;, goog.date.Interval.fromIsoString(duration11));
<a name="line1096"></a>
<a name="line1097"></a>  var duration12 = &#39;PT.5S&#39;;
<a name="line1098"></a>  assertNull(&#39;invalid seconds, missing integer part&#39;,
<a name="line1099"></a>             goog.date.Interval.fromIsoString(duration12));
<a name="line1100"></a>
<a name="line1101"></a>  var duration13 = &#39;PT1.S&#39;;
<a name="line1102"></a>  assertNull(&#39;invalid seconds, missing fractional part&#39;,
<a name="line1103"></a>             goog.date.Interval.fromIsoString(duration13));
<a name="line1104"></a>}
<a name="line1105"></a>
<a name="line1106"></a>
<a name="line1107"></a>function testGetTotalSeconds() {
<a name="line1108"></a>  var duration = new goog.date.Interval(0, 0, 2, 3, 4, 5);
<a name="line1109"></a>  assertEquals(&#39;seconds in 2d3h4m5s&#39;, 2 * 86400 + 3 * 3600 + 4 * 60 + 5,
<a name="line1110"></a>      duration.getTotalSeconds());
<a name="line1111"></a>}
<a name="line1112"></a>
<a name="line1113"></a>
<a name="line1114"></a>function testIsDateLikeWithGoogDateTime() {
<a name="line1115"></a>  var jsDate = new Date();
<a name="line1116"></a>  var googDate = new goog.date.DateTime();
<a name="line1117"></a>  var string = &#39;foo&#39;;
<a name="line1118"></a>  var number = 1;
<a name="line1119"></a>  var nullVar = null;
<a name="line1120"></a>  var notDefined;
<a name="line1121"></a>
<a name="line1122"></a>  assertTrue(&#39;js Date should be date-like&#39;, goog.isDateLike(jsDate));
<a name="line1123"></a>  assertTrue(&#39;goog Date should be date-like&#39;, goog.isDateLike(googDate));
<a name="line1124"></a>  assertFalse(&#39;string should not be date-like&#39;, goog.isDateLike(string));
<a name="line1125"></a>  assertFalse(&#39;number should not be date-like&#39;, goog.isDateLike(number));
<a name="line1126"></a>  assertFalse(&#39;nullVar should not be date-like&#39;, goog.isDateLike(nullVar));
<a name="line1127"></a>  assertFalse(&#39;undefined should not be date-like&#39;, goog.isDateLike(notDefined));
<a name="line1128"></a>}
<a name="line1129"></a>
<a name="line1130"></a>
<a name="line1131"></a>function testDateTimezone() {
<a name="line1132"></a>  var d = new goog.date.DateTime(2006, 01, 01, 12, 00, 00);
<a name="line1133"></a>  d.add(new goog.date.Interval(goog.date.Interval.MINUTES,
<a name="line1134"></a>                               d.getTimezoneOffset()));
<a name="line1135"></a>  var d2 = new goog.date.DateTime(2006, 01, 01, 12, 00, 00);
<a name="line1136"></a>  assertEquals(&#39;Compensate for timezone and compare with UTC date/time&#39;,
<a name="line1137"></a>               d.toIsoString(true), d2.toUTCIsoString(true));
<a name="line1138"></a>}
<a name="line1139"></a>
<a name="line1140"></a>
<a name="line1141"></a>function testToUsTimeString() {
<a name="line1142"></a>  var doPad = true;
<a name="line1143"></a>  var doShowPm = true;
<a name="line1144"></a>  var dontPad = false;
<a name="line1145"></a>  var dontShowPm = false;
<a name="line1146"></a>
<a name="line1147"></a>  // 12am
<a name="line1148"></a>  var d = new goog.date.DateTime(2007, 1, 14);
<a name="line1149"></a>  assertEquals(&#39;12am test 1&#39;, &#39;12:00am&#39;, d.toUsTimeString());
<a name="line1150"></a>  assertEquals(&#39;12am test 2&#39;, &#39;12:00am&#39;, d.toUsTimeString(doPad));
<a name="line1151"></a>  assertEquals(&#39;12am test 3&#39;, &#39;12:00am&#39;, d.toUsTimeString(dontPad));
<a name="line1152"></a>  assertEquals(&#39;12am test 4&#39;, &#39;12:00am&#39;, d.toUsTimeString(doPad, doShowPm));
<a name="line1153"></a>  assertEquals(&#39;12am test 5&#39;, &#39;00:00&#39;, d.toUsTimeString(doPad, dontShowPm));
<a name="line1154"></a>  assertEquals(&#39;12am test 6&#39;, &#39;12:00am&#39;, d.toUsTimeString(dontPad, doShowPm));
<a name="line1155"></a>  assertEquals(&#39;12am test 7&#39;, &#39;0:00&#39;, d.toUsTimeString(dontPad, dontShowPm));
<a name="line1156"></a>
<a name="line1157"></a>  // 9am
<a name="line1158"></a>  d = new goog.date.DateTime(2007, 1, 14, 9);
<a name="line1159"></a>  assertEquals(&#39;9am test 1&#39;, &#39;9:00am&#39;, d.toUsTimeString());
<a name="line1160"></a>  assertEquals(&#39;9am test 2&#39;, &#39;09:00am&#39;, d.toUsTimeString(doPad));
<a name="line1161"></a>  assertEquals(&#39;9am test 3&#39;, &#39;9:00am&#39;, d.toUsTimeString(dontPad));
<a name="line1162"></a>  assertEquals(&#39;9am test 4&#39;, &#39;09:00am&#39;, d.toUsTimeString(doPad, doShowPm));
<a name="line1163"></a>  assertEquals(&#39;9am test 5&#39;, &#39;09:00&#39;, d.toUsTimeString(doPad, dontShowPm));
<a name="line1164"></a>  assertEquals(&#39;9am test 6&#39;, &#39;9:00am&#39;, d.toUsTimeString(dontPad, doShowPm));
<a name="line1165"></a>  assertEquals(&#39;9am test 7&#39;, &#39;9:00&#39;, d.toUsTimeString(dontPad, dontShowPm));
<a name="line1166"></a>
<a name="line1167"></a>  // 12pm
<a name="line1168"></a>  d = new goog.date.DateTime(2007, 1, 14, 12);
<a name="line1169"></a>  assertEquals(&#39;12pm test 1&#39;, &#39;12:00pm&#39;, d.toUsTimeString());
<a name="line1170"></a>  assertEquals(&#39;12pm test 2&#39;, &#39;12:00pm&#39;, d.toUsTimeString(doPad));
<a name="line1171"></a>  assertEquals(&#39;12pm test 3&#39;, &#39;12:00pm&#39;, d.toUsTimeString(dontPad));
<a name="line1172"></a>  assertEquals(&#39;12pm test 4&#39;, &#39;12:00pm&#39;, d.toUsTimeString(doPad, doShowPm));
<a name="line1173"></a>  assertEquals(&#39;12pm test 5&#39;, &#39;12:00&#39;, d.toUsTimeString(doPad, dontShowPm));
<a name="line1174"></a>  assertEquals(&#39;12pm test 6&#39;, &#39;12:00pm&#39;, d.toUsTimeString(dontPad, doShowPm));
<a name="line1175"></a>  assertEquals(&#39;12pm test 7&#39;, &#39;12:00&#39;, d.toUsTimeString(dontPad, dontShowPm));
<a name="line1176"></a>
<a name="line1177"></a>  // 6pm
<a name="line1178"></a>  d = new goog.date.DateTime(2007, 1, 14, 18);
<a name="line1179"></a>  assertEquals(&#39;6pm test 1&#39;, &#39;6:00pm&#39;, d.toUsTimeString());
<a name="line1180"></a>  assertEquals(&#39;6pm test 2&#39;, &#39;06:00pm&#39;, d.toUsTimeString(doPad));
<a name="line1181"></a>  assertEquals(&#39;6pm test 3&#39;, &#39;6:00pm&#39;, d.toUsTimeString(dontPad));
<a name="line1182"></a>  assertEquals(&#39;6pm test 4&#39;, &#39;06:00pm&#39;, d.toUsTimeString(doPad, doShowPm));
<a name="line1183"></a>  assertEquals(&#39;6pm test 5&#39;, &#39;06:00&#39;, d.toUsTimeString(doPad, dontShowPm));
<a name="line1184"></a>  assertEquals(&#39;6pm test 6&#39;, &#39;6:00pm&#39;, d.toUsTimeString(dontPad, doShowPm));
<a name="line1185"></a>  assertEquals(&#39;6pm test 7&#39;, &#39;6:00&#39;, d.toUsTimeString(dontPad, dontShowPm));
<a name="line1186"></a>
<a name="line1187"></a>  // 6:01pm
<a name="line1188"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 1);
<a name="line1189"></a>  assertEquals(&#39;6:01pm test 1&#39;, &#39;6:01pm&#39;, d.toUsTimeString());
<a name="line1190"></a>  assertEquals(&#39;6:01pm test 2&#39;, &#39;06:01pm&#39;, d.toUsTimeString(doPad));
<a name="line1191"></a>  assertEquals(&#39;6:01pm test 3&#39;, &#39;6:01pm&#39;, d.toUsTimeString(dontPad));
<a name="line1192"></a>  assertEquals(&#39;6:01pm test 4&#39;, &#39;06:01pm&#39;, d.toUsTimeString(doPad, doShowPm));
<a name="line1193"></a>  assertEquals(&#39;6:01pm test 5&#39;, &#39;06:01&#39;, d.toUsTimeString(doPad, dontShowPm));
<a name="line1194"></a>  assertEquals(&#39;6:01pm test 6&#39;, &#39;6:01pm&#39;, d.toUsTimeString(dontPad, doShowPm));
<a name="line1195"></a>  assertEquals(&#39;6:01pm test 7&#39;, &#39;6:01&#39;, d.toUsTimeString(dontPad, dontShowPm));
<a name="line1196"></a>
<a name="line1197"></a>  // 6:35pm
<a name="line1198"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35);
<a name="line1199"></a>  assertEquals(&#39;6:35pm test 1&#39;, &#39;6:35pm&#39;, d.toUsTimeString());
<a name="line1200"></a>  assertEquals(&#39;6:35pm test 2&#39;, &#39;06:35pm&#39;, d.toUsTimeString(doPad));
<a name="line1201"></a>  assertEquals(&#39;6:35pm test 3&#39;, &#39;6:35pm&#39;, d.toUsTimeString(dontPad));
<a name="line1202"></a>  assertEquals(&#39;6:35pm test 4&#39;, &#39;06:35pm&#39;, d.toUsTimeString(doPad, doShowPm));
<a name="line1203"></a>  assertEquals(&#39;6:35pm test 5&#39;, &#39;06:35&#39;, d.toUsTimeString(doPad, dontShowPm));
<a name="line1204"></a>  assertEquals(&#39;6:35pm test 6&#39;, &#39;6:35pm&#39;, d.toUsTimeString(dontPad, doShowPm));
<a name="line1205"></a>  assertEquals(&#39;6:35pm test 7&#39;, &#39;6:35&#39;, d.toUsTimeString(dontPad, dontShowPm));
<a name="line1206"></a>
<a name="line1207"></a>  // omit zero minutes
<a name="line1208"></a>  d = new goog.date.DateTime(2007, 1, 14, 18);
<a name="line1209"></a>  assertEquals(&#39;omit zero 1&#39;, &#39;6:00pm&#39;, d.toUsTimeString(dontPad,
<a name="line1210"></a>                                                         doShowPm,
<a name="line1211"></a>                                                         false));
<a name="line1212"></a>  assertEquals(&#39;omit zero 2&#39;, &#39;6pm&#39;, d.toUsTimeString(dontPad,
<a name="line1213"></a>                                                      doShowPm,
<a name="line1214"></a>                                                      true));
<a name="line1215"></a>
<a name="line1216"></a>  // but don&#39;t omit zero minutes if not actually zero minutes
<a name="line1217"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 1);
<a name="line1218"></a>  assertEquals(&#39;omit zero 3&#39;, &#39;6:01pm&#39;, d.toUsTimeString(dontPad,
<a name="line1219"></a>                                                         doShowPm,
<a name="line1220"></a>                                                         false));
<a name="line1221"></a>  assertEquals(&#39;omit zero 4&#39;, &#39;6:01pm&#39;, d.toUsTimeString(dontPad,
<a name="line1222"></a>                                                         doShowPm,
<a name="line1223"></a>                                                         true));
<a name="line1224"></a>}
<a name="line1225"></a>
<a name="line1226"></a>
<a name="line1227"></a>function testToIsoTimeString() {
<a name="line1228"></a>  // 00:00
<a name="line1229"></a>  var d = new goog.date.DateTime(2007, 1, 14);
<a name="line1230"></a>  assertEquals(&#39;00:00&#39;, &#39;00:00:00&#39;, d.toIsoTimeString());
<a name="line1231"></a>
<a name="line1232"></a>  // 09:00
<a name="line1233"></a>  d = new goog.date.DateTime(2007, 1, 14, 9);
<a name="line1234"></a>  assertEquals(&#39;09:00&#39;, &#39;09:00:00&#39;, d.toIsoTimeString());
<a name="line1235"></a>
<a name="line1236"></a>  // 12:00
<a name="line1237"></a>  d = new goog.date.DateTime(2007, 1, 14, 12);
<a name="line1238"></a>  assertEquals(&#39;12:00&#39;, &#39;12:00:00&#39;, d.toIsoTimeString());
<a name="line1239"></a>
<a name="line1240"></a>  // 18:00
<a name="line1241"></a>  d = new goog.date.DateTime(2007, 1, 14, 18);
<a name="line1242"></a>  assertEquals(&#39;18:00&#39;, &#39;18:00:00&#39;, d.toIsoTimeString());
<a name="line1243"></a>
<a name="line1244"></a>  // 18:01
<a name="line1245"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 1);
<a name="line1246"></a>  assertEquals(&#39;18:01&#39;, &#39;18:01:00&#39;, d.toIsoTimeString());
<a name="line1247"></a>
<a name="line1248"></a>  // 18:35
<a name="line1249"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35);
<a name="line1250"></a>  assertEquals(&#39;18:35&#39;, &#39;18:35:00&#39;, d.toIsoTimeString());
<a name="line1251"></a>
<a name="line1252"></a>  // 18:35:01
<a name="line1253"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35, 1);
<a name="line1254"></a>  assertEquals(&#39;18:35:01&#39;, &#39;18:35:01&#39;, d.toIsoTimeString());
<a name="line1255"></a>
<a name="line1256"></a>  // 18:35:11
<a name="line1257"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35, 11);
<a name="line1258"></a>  assertEquals(&#39;18:35:11&#39;, &#39;18:35:11&#39;, d.toIsoTimeString());
<a name="line1259"></a>
<a name="line1260"></a>  // 18:35:11 &gt;&gt; 18:35
<a name="line1261"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35, 11);
<a name="line1262"></a>  assertEquals(&#39;18:35:11 no secs&#39;, &#39;18:35&#39;, d.toIsoTimeString(false));
<a name="line1263"></a>}
<a name="line1264"></a>
<a name="line1265"></a>
<a name="line1266"></a>function testToXmlDateTimeString() {
<a name="line1267"></a>  var d = new goog.date.DateTime(2007, 1, 14);
<a name="line1268"></a>  assertEquals(&#39;2007-02-14&#39;,
<a name="line1269"></a>      &#39;2007-02-14T00:00:00&#39;,
<a name="line1270"></a>      d.toXmlDateTime());
<a name="line1271"></a>
<a name="line1272"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35, 1);
<a name="line1273"></a>  assertEquals(&#39;2007-02-14, 8:35:01, timezone==undefined&#39;,
<a name="line1274"></a>      &#39;2007-02-14T18:35:01&#39;,
<a name="line1275"></a>      d.toXmlDateTime());
<a name="line1276"></a>
<a name="line1277"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35, 1);
<a name="line1278"></a>  assertEquals(&#39;2007-02-14, 8:35:01, timezone==false&#39;,
<a name="line1279"></a>      &#39;2007-02-14T18:35:01&#39;,
<a name="line1280"></a>      d.toXmlDateTime(false));
<a name="line1281"></a>
<a name="line1282"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35, 1);
<a name="line1283"></a>  assertEquals(&#39;2007-02-14, 8:35:01, timezone==true&#39;,
<a name="line1284"></a>      &#39;2007-02-14T18:35:01&#39; + d.getTimezoneOffsetString(),
<a name="line1285"></a>      d.toXmlDateTime(true));
<a name="line1286"></a>}
<a name="line1287"></a>
<a name="line1288"></a>
<a name="line1289"></a>function testClone() {
<a name="line1290"></a>  var d = new goog.date.DateTime(2007, 1, 14, 18, 35, 1);
<a name="line1291"></a>  var d2 = d.clone();
<a name="line1292"></a>  assertTrue(&#39;datetimes equal&#39;, d.equals(d2));
<a name="line1293"></a>
<a name="line1294"></a>  d = new goog.date.DateTime(2007, 1, 14, 18, 35, 1, 310);
<a name="line1295"></a>  d2 = d.clone();
<a name="line1296"></a>  assertTrue(&#39;datetimes with milliseconds equal&#39;, d.equals(d2));
<a name="line1297"></a>
<a name="line1298"></a>  d = new goog.date.Date(2007, 1, 14);
<a name="line1299"></a>  d2 = d.clone();
<a name="line1300"></a>  assertTrue(&#39;dates equal&#39;, d.equals(d2));
<a name="line1301"></a>
<a name="line1302"></a>  // 1 year, 6 months, 15 days, 12 hours, 30 minutes, 30 seconds
<a name="line1303"></a>  var i = new goog.date.Interval(1, 6, 15, 12, 30, 30);
<a name="line1304"></a>  var i2 = i.clone();
<a name="line1305"></a>  assertTrue(&#39;intervals equal&#39;, i.equals(i2));
<a name="line1306"></a>
<a name="line1307"></a>  i = new goog.date.Interval(goog.date.Interval.DAYS, -1);
<a name="line1308"></a>  i2 = i.clone();
<a name="line1309"></a>  assertTrue(&#39;day intervals equal&#39;, i.equals(i2));
<a name="line1310"></a>
<a name="line1311"></a>  // Brasilia dst
<a name="line1312"></a>  d = new goog.date.Date(2008, goog.date.month.OCT, 18);
<a name="line1313"></a>  d.add(new goog.date.Interval(goog.date.Interval.DAYS, 1));
<a name="line1314"></a>  d2 = d.clone();
<a name="line1315"></a>  assertTrue(&#39;dates equal&#39;, d.equals(d2));
<a name="line1316"></a>}
<a name="line1317"></a>
<a name="line1318"></a>function testValueOf() {
<a name="line1319"></a>  var date1 = new goog.date.DateTime(2008, 11, 26, 15, 40, 0);
<a name="line1320"></a>  var date2 = new goog.date.Date(2008, 11, 27);
<a name="line1321"></a>  var date3 = new goog.date.DateTime(2008, 11, 26, 15, 40, 1);
<a name="line1322"></a>  var nativeDate = new Date();
<a name="line1323"></a>  nativeDate.setFullYear(2008, 11, 26);
<a name="line1324"></a>  nativeDate.setHours(15, 40, 0, 0);
<a name="line1325"></a>  assertEquals(date1.valueOf(), nativeDate.valueOf());
<a name="line1326"></a>  assertFalse(date1 &lt; date1);
<a name="line1327"></a>  assertTrue(date1 &lt;= date1);
<a name="line1328"></a>  assertTrue(date1 &lt; date2);
<a name="line1329"></a>  assertTrue(date2 &gt; date3);
<a name="line1330"></a>}
<a name="line1331"></a>
<a name="line1332"></a>function isWinxpSafari4() {
<a name="line1333"></a>  return goog.userAgent.product.SAFARI &amp;&amp;
<a name="line1334"></a>      goog.userAgent.product.isVersion(&#39;4&#39;) &amp;&amp;
<a name="line1335"></a>      !goog.userAgent.product.isVersion(&#39;5&#39;) &amp;&amp;
<a name="line1336"></a>      goog.userAgent.WINDOWS &amp;&amp;
<a name="line1337"></a>      goog.userAgent.platform.isVersion(&#39;5.0&#39;) &amp;&amp;
<a name="line1338"></a>      !goog.userAgent.platform.isVersion(&#39;6.0&#39;);
<a name="line1339"></a>}
<a name="line1340"></a>
<a name="line1341"></a>function testDateCompare() {
<a name="line1342"></a>  // May 16th, 2011, 3:17:36.500
<a name="line1343"></a>  var date1 = new goog.date.DateTime(2011,
<a name="line1344"></a>      goog.date.month.MAY, 16, 15, 17, 36, 500);
<a name="line1345"></a>
<a name="line1346"></a>  // May 16th, 2011, 3:17:36.501
<a name="line1347"></a>  var date2 = new goog.date.DateTime(2011,
<a name="line1348"></a>      goog.date.month.MAY, 16, 15, 17, 36, 501);
<a name="line1349"></a>
<a name="line1350"></a>  // May 16th, 2011, 3:17:36.501
<a name="line1351"></a>  var date3 = new goog.date.DateTime(2011,
<a name="line1352"></a>      goog.date.month.MAY, 16, 15, 17, 36, 502);
<a name="line1353"></a>
<a name="line1354"></a>  assertEquals(0, goog.date.Date.compare(date1.clone(), date1.clone()));
<a name="line1355"></a>  assertEquals(-1, goog.date.Date.compare(date1, date2));
<a name="line1356"></a>  assertEquals(1, goog.date.Date.compare(date2, date1));
<a name="line1357"></a>
<a name="line1358"></a>  var dates = [date2, date3, date1];
<a name="line1359"></a>  goog.array.sort(dates, goog.date.Date.compare);
<a name="line1360"></a>  assertArrayEquals(&#39;Dates should be sorted in time.&#39;,
<a name="line1361"></a>      [date1, date2, date3], dates);
<a name="line1362"></a>
<a name="line1363"></a>  // Assert a known millisecond difference between two points in time.
<a name="line1364"></a>  assertEquals(-19129478,
<a name="line1365"></a>      goog.date.Date.compare(
<a name="line1366"></a>          new goog.date.DateTime(1982, goog.date.month.MAR, 12, 6, 48, 32, 354),
<a name="line1367"></a>          new goog.date.DateTime(
<a name="line1368"></a>              1982, goog.date.month.MAR, 12, 12, 07, 21, 832)));
<a name="line1369"></a>
<a name="line1370"></a>  // Test dates before the year 0.  Dates are Talk Like a Pirate Day, and
<a name="line1371"></a>  // Towel Day, 300 B.C. (and before pirates).
<a name="line1372"></a>
<a name="line1373"></a>  var pirateDay = new goog.date.Date(-300, goog.date.month.SEP, 2);
<a name="line1374"></a>  var towelDay = new goog.date.Date(-300, goog.date.month.MAY, 12);
<a name="line1375"></a>
<a name="line1376"></a>  assertEquals(&#39;Dates should be 113 days apart.&#39;,
<a name="line1377"></a>      113 * 24 * 60 * 60 * 1000,
<a name="line1378"></a>      goog.date.Date.compare(pirateDay, towelDay));
<a name="line1379"></a>}
<a name="line1380"></a>
<a name="line1381"></a>function testDateCompareDateLikes() {
<a name="line1382"></a>  var nativeDate = new Date(2011, 4, 16, 15, 17, 36, 500);
<a name="line1383"></a>  var closureDate = new goog.date.DateTime(2011,
<a name="line1384"></a>      goog.date.month.MAY, 16, 15, 17, 36, 500);
<a name="line1385"></a>
<a name="line1386"></a>  assertEquals(0, goog.date.Date.compare(nativeDate, closureDate));
<a name="line1387"></a>
<a name="line1388"></a>  nativeDate.setMilliseconds(499);
<a name="line1389"></a>  assertEquals(-1, goog.date.Date.compare(nativeDate, closureDate));
<a name="line1390"></a>
<a name="line1391"></a>  nativeDate.setMilliseconds(501);
<a name="line1392"></a>  assertEquals(1, goog.date.Date.compare(nativeDate, closureDate));
<a name="line1393"></a>}
<a name="line1394"></a>
<a name="line1395"></a>function testIsMidnight() {
<a name="line1396"></a>  assertTrue(new goog.date.DateTime(2013, 0, 1).isMidnight());
<a name="line1397"></a>  assertFalse(new goog.date.DateTime(2013, 0, 1, 1).isMidnight());
<a name="line1398"></a>  assertFalse(new goog.date.DateTime(2013, 0, 1, 0, 1).isMidnight());
<a name="line1399"></a>  assertFalse(new goog.date.DateTime(2013, 0, 1, 0, 0, 1).isMidnight());
<a name="line1400"></a>  assertFalse(new goog.date.DateTime(2013, 0, 1, 0, 0, 0, 1).isMidnight());
<a name="line1401"></a>}
<a name="line1402"></a>
<a name="line1403"></a>function testMinMax() {
<a name="line1404"></a>  // Comparison of two goog.date.DateTimes
<a name="line1405"></a>  var dateTime1 = new goog.date.DateTime(2000, 0, 1);
<a name="line1406"></a>  var dateTime2 = new goog.date.DateTime(2000, 0, 1, 0, 0, 0, 1);
<a name="line1407"></a>  assertEquals(dateTime1, goog.date.min(dateTime1, dateTime2));
<a name="line1408"></a>  assertEquals(dateTime1, goog.date.min(dateTime2, dateTime1));
<a name="line1409"></a>  assertEquals(dateTime2, goog.date.max(dateTime1, dateTime2));
<a name="line1410"></a>  assertEquals(dateTime2, goog.date.max(dateTime2, dateTime1));
<a name="line1411"></a>
<a name="line1412"></a>  // Comparison of two goog.date.Dates
<a name="line1413"></a>  var date1 = new goog.date.Date(2000, 0, 1);
<a name="line1414"></a>  var date2 = new goog.date.Date(2000, 0, 2);
<a name="line1415"></a>  assertEquals(date1, goog.date.min(date1, date2));
<a name="line1416"></a>
<a name="line1417"></a>  // Comparison of native Dates.
<a name="line1418"></a>  var jsDate1 = new Date(2000, 0, 1);
<a name="line1419"></a>  var jsDate2 = new Date(2000, 0, 2);
<a name="line1420"></a>  assertEquals(jsDate1, goog.date.min(jsDate1, jsDate2));
<a name="line1421"></a>  assertEquals(jsDate2, goog.date.max(jsDate1, jsDate2));
<a name="line1422"></a>
<a name="line1423"></a>  // Comparison of different types.
<a name="line1424"></a>  assertEquals(date1, goog.date.min(date1, dateTime2));
<a name="line1425"></a>  assertEquals(dateTime2, goog.date.min(date2, dateTime2));
<a name="line1426"></a>  assertEquals(date1, goog.date.min(date1, jsDate2));
<a name="line1427"></a>  assertEquals(jsDate2, goog.date.max(dateTime1, jsDate2));
<a name="line1428"></a>}
</pre>


</body>
</html>
